Commit c00c6b1d1ede7c5bd66d46345ebc3a2814f4bdbb

Authored by Adhidarma Hadiwinoto
1 parent 2386b082b2
Exists in master

Add info why use sd-notify instead of systemd-notify

Showing 1 changed file with 3 additions and 1 deletions Inline Diff

1 /* eslint-disable global-require */ 1 /* eslint-disable global-require */
2 /* eslint-disable import/no-extraneous-dependencies */ 2 /* eslint-disable import/no-extraneous-dependencies */
3 3
4 const MODULE_NAME = 'KOMODO-SDK.SD-NOTIFY'; 4 const MODULE_NAME = 'KOMODO-SDK.SD-NOTIFY';
5 5
6 const logger = require('tektrans-logger'); 6 const logger = require('tektrans-logger');
7 const matrix = require('./matrix'); 7 const matrix = require('./matrix');
8 8
9 const notifyUseSdNotify = () => { 9 const notifyUseSdNotify = () => {
10 try { 10 try {
11 const sdNotify = require('sd-notify'); 11 const sdNotify = require('sd-notify');
12 12
13 sdNotify.ready(); 13 sdNotify.ready();
14 matrix.systemd_notified = new Date(); 14 matrix.systemd_notified = new Date();
15 15
16 logger.info(`${MODULE_NAME} 701F8400: Systemd ready notification has been sent using sd-notify module`); 16 logger.info(`${MODULE_NAME} 701F8400: Systemd ready notification has been sent using sd-notify module`);
17 } catch (e) { 17 } catch (e) {
18 logger.warn(`${MODULE_NAME} A6C99938: Optional dependency not found: sd-notify`); 18 logger.warn(`${MODULE_NAME} A6C99938: Optional dependency not found: sd-notify`);
19 } 19 }
20 }; 20 };
21 21
22 /** 22 /**
23 * 23 *
24 * @param {string} statusMsg 24 * @param {string} statusMsg
25 * @returns 25 * @returns
26 */ 26 */
27 module.exports = async (statusMsg) => { 27 module.exports = async (statusMsg) => {
28 const { ppid } = process; 28 const { ppid } = process;
29 29
30 if (ppid !== 1) { 30 if (ppid !== 1) {
31 logger.verbose(`${MODULE_NAME} 74A5B2AF: No need to notify systemd`, { ppid }); 31 logger.verbose(`${MODULE_NAME} 74A5B2AF: No need to notify systemd`, { ppid });
32 return; 32 return;
33 } 33 }
34 34
35 try { 35 try {
36 const notify = require('systemd-notify'); 36 const notify = require('systemd-notify');
37 37
38 const status = statusMsg || 'Ready to go'; 38 const status = statusMsg || 'Ready to go';
39 39
40 logger.verbose(`${MODULE_NAME} 3B8DF3BC: Trying to notify systemd using systemd-notify package`, { status }); 40 logger.verbose(`${MODULE_NAME} 3B8DF3BC: Trying to notify systemd using systemd-notify package`, { status });
41 41
42 await notify({ 42 await notify({
43 ready: true, 43 ready: true,
44 status, 44 status,
45 }); 45 });
46 } catch (e) { 46 } catch (e) {
47 logger.verbose(`${MODULE_NAME} 488B3245: Trying to notify sd-notify package`); 47 logger.verbose(`${MODULE_NAME} 488B3245: Trying to notify sd-notify package`, {
48 why: e.message || e.toString(),
49 });
48 notifyUseSdNotify(); 50 notifyUseSdNotify();
49 } 51 }
50 }; 52 };
51 53