Commit 69b66c6166070aa2cdaf4d09726e4c25f27996bb
1 parent
e879b83c41
Exists in
master
Catch e on using systemd-notify binary
Showing 3 changed files with 30 additions and 53 deletions Side-by-side Diff
package-lock.json
... | ... | @@ -37,8 +37,7 @@ |
37 | 37 | "tektrans-logger": "^1.2.5", |
38 | 38 | "uniqid": "^4.1.1", |
39 | 39 | "url-join": "^4.0.1", |
40 | - "uuid": "^9.0.0", | |
41 | - "which": "^4.0.0" | |
40 | + "uuid": "^9.0.0" | |
42 | 41 | }, |
43 | 42 | "devDependencies": { |
44 | 43 | "auto-changelog": "^2.4.0", |
... | ... | @@ -2116,14 +2115,6 @@ |
2116 | 2115 | "url": "https://github.com/sponsors/ljharb" |
2117 | 2116 | } |
2118 | 2117 | }, |
2119 | - "node_modules/isexe": { | |
2120 | - "version": "3.1.1", | |
2121 | - "resolved": "https://registry.npmjs.org/isexe/-/isexe-3.1.1.tgz", | |
2122 | - "integrity": "sha512-LpB/54B+/2J5hqQ7imZHfdU31OlgQqx7ZicVlkm9kzg9/w8GKLEcFfJl/t7DCEDueOyBAD6zCCwTO6Fzs0NoEQ==", | |
2123 | - "engines": { | |
2124 | - "node": ">=16" | |
2125 | - } | |
2126 | - }, | |
2127 | 2118 | "node_modules/isstream": { |
2128 | 2119 | "version": "0.1.2", |
2129 | 2120 | "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", |
... | ... | @@ -3552,20 +3543,6 @@ |
3552 | 3543 | "webidl-conversions": "^3.0.0" |
3553 | 3544 | } |
3554 | 3545 | }, |
3555 | - "node_modules/which": { | |
3556 | - "version": "4.0.0", | |
3557 | - "resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz", | |
3558 | - "integrity": "sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==", | |
3559 | - "dependencies": { | |
3560 | - "isexe": "^3.1.1" | |
3561 | - }, | |
3562 | - "bin": { | |
3563 | - "node-which": "bin/which.js" | |
3564 | - }, | |
3565 | - "engines": { | |
3566 | - "node": "^16.13.0 || >=18.0.0" | |
3567 | - } | |
3568 | - }, | |
3569 | 3546 | "node_modules/which-boxed-primitive": { |
3570 | 3547 | "version": "1.0.2", |
3571 | 3548 | "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz", |
... | ... | @@ -5236,11 +5213,6 @@ |
5236 | 5213 | "call-bind": "^1.0.2" |
5237 | 5214 | } |
5238 | 5215 | }, |
5239 | - "isexe": { | |
5240 | - "version": "3.1.1", | |
5241 | - "resolved": "https://registry.npmjs.org/isexe/-/isexe-3.1.1.tgz", | |
5242 | - "integrity": "sha512-LpB/54B+/2J5hqQ7imZHfdU31OlgQqx7ZicVlkm9kzg9/w8GKLEcFfJl/t7DCEDueOyBAD6zCCwTO6Fzs0NoEQ==" | |
5243 | - }, | |
5244 | 5216 | "isstream": { |
5245 | 5217 | "version": "0.1.2", |
5246 | 5218 | "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", |
... | ... | @@ -6312,14 +6284,6 @@ |
6312 | 6284 | "webidl-conversions": "^3.0.0" |
6313 | 6285 | } |
6314 | 6286 | }, |
6315 | - "which": { | |
6316 | - "version": "4.0.0", | |
6317 | - "resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz", | |
6318 | - "integrity": "sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==", | |
6319 | - "requires": { | |
6320 | - "isexe": "^3.1.1" | |
6321 | - } | |
6322 | - }, | |
6323 | 6287 | "which-boxed-primitive": { |
6324 | 6288 | "version": "1.0.2", |
6325 | 6289 | "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz", |
package.json
sd-notify.js
... | ... | @@ -3,15 +3,11 @@ |
3 | 3 | |
4 | 4 | const MODULE_NAME = 'KOMODO-SDK.SD-NOTIFY'; |
5 | 5 | |
6 | -const childProcess = require('child_process'); | |
7 | -const which = require('which'); | |
6 | +const util = require('util'); | |
8 | 7 | const logger = require('tektrans-logger'); |
9 | 8 | const matrix = require('./matrix'); |
10 | 9 | |
11 | -const hasSystemdNotifyBin = async () => { | |
12 | - const result = await which('systemd-notify', { nothrow: true }); | |
13 | - return result; | |
14 | -}; | |
10 | +const exec = util.promisify(require('node:child_process').exec); | |
15 | 11 | |
16 | 12 | const notifyUseSystemdNotify = async (statusMsg) => { |
17 | 13 | try { |
... | ... | @@ -27,6 +23,8 @@ const notifyUseSystemdNotify = async (statusMsg) => { |
27 | 23 | pid: process.pid, |
28 | 24 | }); |
29 | 25 | |
26 | + logger.info(`${MODULE_NAME} B905A857: Systemd ready notification has been sent using systemd-notify package`); | |
27 | + | |
30 | 28 | return true; |
31 | 29 | } catch (e) { |
32 | 30 | logger.verbose(`${MODULE_NAME} 488B3245: Failed to notify using systemd-notify package`, { |
... | ... | @@ -47,8 +45,28 @@ const notifyUseSdNotify = () => { |
47 | 45 | matrix.systemd_notified = new Date(); |
48 | 46 | |
49 | 47 | logger.info(`${MODULE_NAME} 701F8400: Systemd ready notification has been sent using sd-notify package`); |
48 | + | |
49 | + return true; | |
50 | 50 | } catch (e) { |
51 | 51 | logger.warn(`${MODULE_NAME} A6C99938: Optional dependency not found: sd-notify`); |
52 | + return false; | |
53 | + } | |
54 | +}; | |
55 | + | |
56 | +const notifyUseBin = async () => { | |
57 | + try { | |
58 | + logger.verbose(`${MODULE_NAME} FFBCF4E3: Trying to notify systemd using systemd-notify bin`); | |
59 | + await exec('systemd-notify --ready'); | |
60 | + logger.info(`${MODULE_NAME} B58921FF: Systemd ready notification has been sent using systemd-notify bin`); | |
61 | + | |
62 | + return true; | |
63 | + } catch (e) { | |
64 | + logger.verbose(`${MODULE_NAME} 75237B65: Failed to notify using systemd-notify bin`, { | |
65 | + eCode: e.code, | |
66 | + eMessage: e.message || e.toString(), | |
67 | + }); | |
68 | + | |
69 | + return false; | |
52 | 70 | } |
53 | 71 | }; |
54 | 72 | |
... | ... | @@ -65,19 +83,15 @@ module.exports = async (statusMsg) => { |
65 | 83 | return; |
66 | 84 | } |
67 | 85 | |
68 | - const successOnUseSystemdNotify = await notifyUseSystemdNotify(statusMsg); | |
69 | - if (successOnUseSystemdNotify) { | |
86 | + const successOnUsingSystemdNotify = await notifyUseSystemdNotify(statusMsg); | |
87 | + if (successOnUsingSystemdNotify) { | |
70 | 88 | return; |
71 | 89 | } |
72 | 90 | |
73 | - const useExec = await hasSystemdNotifyBin(); | |
74 | - if (useExec) { | |
75 | - logger.verbose(`${MODULE_NAME} FFBCF4E3: Trying to notify systemd using systemd-notify bin`); | |
76 | - childProcess.exec('systemd-notify --ready'); | |
91 | + const successOnUsingBin = await notifyUseBin(); | |
92 | + if (successOnUsingBin) { | |
77 | 93 | return; |
78 | 94 | } |
79 | 95 | |
80 | - logger.verbose(`${MODULE_NAME} 9ADD3807: systemd-notify binary not found, fallback to sd-notify package`); | |
81 | - | |
82 | 96 | notifyUseSdNotify(); |
83 | 97 | }; |