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