Commit aea93bf53bb747f842ce6cf5f302dfa24a1d8946
1 parent
fa0179cbeb
Exists in
master
Specify pid on calling systemd-notify
Showing 1 changed file with 1 additions and 0 deletions Inline Diff
sd-notify.js
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 | pid: process.pid, | ||
45 | }); | 46 | }); |
46 | } catch (e) { | 47 | } catch (e) { |
47 | logger.verbose(`${MODULE_NAME} 488B3245: Trying to notify sd-notify package`, { | 48 | logger.verbose(`${MODULE_NAME} 488B3245: Trying to notify sd-notify package`, { |
48 | why: e.message || e.toString(), | 49 | why: e.message || e.toString(), |
49 | }); | 50 | }); |
50 | notifyUseSdNotify(); | 51 | notifyUseSdNotify(); |
51 | } | 52 | } |
52 | }; | 53 | }; |
53 | 54 |