Commit 3a96ac45dffa26630fc939812236230fad8afe0e
1 parent
4869378afd
Exists in
master
Experimental using systemd-notify package
Showing 3 changed files with 111 additions and 28 deletions Side-by-side Diff
package-lock.json
... | ... | @@ -37,13 +37,15 @@ |
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" | |
40 | + "uuid": "^9.0.0", | |
41 | + "which": "^4.0.0" | |
41 | 42 | }, |
42 | 43 | "devDependencies": { |
43 | 44 | "auto-changelog": "^2.4.0", |
44 | 45 | "eslint": "^8.6.0", |
45 | 46 | "eslint-config-airbnb-base": "^15.0.0", |
46 | - "eslint-plugin-import": "^2.25.4" | |
47 | + "eslint-plugin-import": "^2.25.4", | |
48 | + "systemd-notify": "^1.0.0" | |
47 | 49 | }, |
48 | 50 | "optionalDependencies": { |
49 | 51 | "sd-notify": "^2.8.0" |
... | ... | @@ -752,6 +754,27 @@ |
752 | 754 | "node": ">= 8" |
753 | 755 | } |
754 | 756 | }, |
757 | + "node_modules/cross-spawn/node_modules/isexe": { | |
758 | + "version": "2.0.0", | |
759 | + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", | |
760 | + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", | |
761 | + "dev": true | |
762 | + }, | |
763 | + "node_modules/cross-spawn/node_modules/which": { | |
764 | + "version": "2.0.2", | |
765 | + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", | |
766 | + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", | |
767 | + "dev": true, | |
768 | + "dependencies": { | |
769 | + "isexe": "^2.0.0" | |
770 | + }, | |
771 | + "bin": { | |
772 | + "node-which": "bin/node-which" | |
773 | + }, | |
774 | + "engines": { | |
775 | + "node": ">= 8" | |
776 | + } | |
777 | + }, | |
755 | 778 | "node_modules/crypt": { |
756 | 779 | "version": "0.0.2", |
757 | 780 | "resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz", |
... | ... | @@ -2094,10 +2117,12 @@ |
2094 | 2117 | } |
2095 | 2118 | }, |
2096 | 2119 | "node_modules/isexe": { |
2097 | - "version": "2.0.0", | |
2098 | - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", | |
2099 | - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", | |
2100 | - "dev": true | |
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 | + } | |
2101 | 2126 | }, |
2102 | 2127 | "node_modules/isstream": { |
2103 | 2128 | "version": "0.1.2", |
... | ... | @@ -3261,6 +3286,12 @@ |
3261 | 3286 | "url": "https://github.com/sponsors/ljharb" |
3262 | 3287 | } |
3263 | 3288 | }, |
3289 | + "node_modules/systemd-notify": { | |
3290 | + "version": "1.0.0", | |
3291 | + "resolved": "https://registry.npmjs.org/systemd-notify/-/systemd-notify-1.0.0.tgz", | |
3292 | + "integrity": "sha512-KP/Qn747dzdOgc7BEk3qd3EZWauwJ+aupqo3Upz134r4WZQJhU+qyJFnGMsMzj/NQf7XfPFq/LQogpqZuZmNXA==", | |
3293 | + "dev": true | |
3294 | + }, | |
3264 | 3295 | "node_modules/tektrans-logger": { |
3265 | 3296 | "version": "1.2.5", |
3266 | 3297 | "resolved": "https://registry.npmjs.org/tektrans-logger/-/tektrans-logger-1.2.5.tgz", |
... | ... | @@ -3522,18 +3553,17 @@ |
3522 | 3553 | } |
3523 | 3554 | }, |
3524 | 3555 | "node_modules/which": { |
3525 | - "version": "2.0.2", | |
3526 | - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", | |
3527 | - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", | |
3528 | - "dev": true, | |
3556 | + "version": "4.0.0", | |
3557 | + "resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz", | |
3558 | + "integrity": "sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==", | |
3529 | 3559 | "dependencies": { |
3530 | - "isexe": "^2.0.0" | |
3560 | + "isexe": "^3.1.1" | |
3531 | 3561 | }, |
3532 | 3562 | "bin": { |
3533 | - "node-which": "bin/node-which" | |
3563 | + "node-which": "bin/which.js" | |
3534 | 3564 | }, |
3535 | 3565 | "engines": { |
3536 | - "node": ">= 8" | |
3566 | + "node": "^16.13.0 || >=18.0.0" | |
3537 | 3567 | } |
3538 | 3568 | }, |
3539 | 3569 | "node_modules/which-boxed-primitive": { |
... | ... | @@ -4190,6 +4220,23 @@ |
4190 | 4220 | "path-key": "^3.1.0", |
4191 | 4221 | "shebang-command": "^2.0.0", |
4192 | 4222 | "which": "^2.0.1" |
4223 | + }, | |
4224 | + "dependencies": { | |
4225 | + "isexe": { | |
4226 | + "version": "2.0.0", | |
4227 | + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", | |
4228 | + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", | |
4229 | + "dev": true | |
4230 | + }, | |
4231 | + "which": { | |
4232 | + "version": "2.0.2", | |
4233 | + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", | |
4234 | + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", | |
4235 | + "dev": true, | |
4236 | + "requires": { | |
4237 | + "isexe": "^2.0.0" | |
4238 | + } | |
4239 | + } | |
4193 | 4240 | } |
4194 | 4241 | }, |
4195 | 4242 | "crypt": { |
... | ... | @@ -5190,10 +5237,9 @@ |
5190 | 5237 | } |
5191 | 5238 | }, |
5192 | 5239 | "isexe": { |
5193 | - "version": "2.0.0", | |
5194 | - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", | |
5195 | - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", | |
5196 | - "dev": true | |
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==" | |
5197 | 5243 | }, |
5198 | 5244 | "isstream": { |
5199 | 5245 | "version": "0.1.2", |
... | ... | @@ -6052,6 +6098,12 @@ |
6052 | 6098 | "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", |
6053 | 6099 | "dev": true |
6054 | 6100 | }, |
6101 | + "systemd-notify": { | |
6102 | + "version": "1.0.0", | |
6103 | + "resolved": "https://registry.npmjs.org/systemd-notify/-/systemd-notify-1.0.0.tgz", | |
6104 | + "integrity": "sha512-KP/Qn747dzdOgc7BEk3qd3EZWauwJ+aupqo3Upz134r4WZQJhU+qyJFnGMsMzj/NQf7XfPFq/LQogpqZuZmNXA==", | |
6105 | + "dev": true | |
6106 | + }, | |
6055 | 6107 | "tektrans-logger": { |
6056 | 6108 | "version": "1.2.5", |
6057 | 6109 | "resolved": "https://registry.npmjs.org/tektrans-logger/-/tektrans-logger-1.2.5.tgz", |
... | ... | @@ -6261,12 +6313,11 @@ |
6261 | 6313 | } |
6262 | 6314 | }, |
6263 | 6315 | "which": { |
6264 | - "version": "2.0.2", | |
6265 | - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", | |
6266 | - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", | |
6267 | - "dev": true, | |
6316 | + "version": "4.0.0", | |
6317 | + "resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz", | |
6318 | + "integrity": "sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==", | |
6268 | 6319 | "requires": { |
6269 | - "isexe": "^2.0.0" | |
6320 | + "isexe": "^3.1.1" | |
6270 | 6321 | } |
6271 | 6322 | }, |
6272 | 6323 | "which-boxed-primitive": { |
package.json
... | ... | @@ -48,13 +48,15 @@ |
48 | 48 | "tektrans-logger": "^1.2.5", |
49 | 49 | "uniqid": "^4.1.1", |
50 | 50 | "url-join": "^4.0.1", |
51 | - "uuid": "^9.0.0" | |
51 | + "uuid": "^9.0.0", | |
52 | + "which": "^4.0.0" | |
52 | 53 | }, |
53 | 54 | "devDependencies": { |
54 | 55 | "auto-changelog": "^2.4.0", |
55 | 56 | "eslint": "^8.6.0", |
56 | 57 | "eslint-config-airbnb-base": "^15.0.0", |
57 | - "eslint-plugin-import": "^2.25.4" | |
58 | + "eslint-plugin-import": "^2.25.4", | |
59 | + "systemd-notify": "^1.0.0" | |
58 | 60 | }, |
59 | 61 | "optionalDependencies": { |
60 | 62 | "sd-notify": "^2.8.0" |
sd-notify.js
... | ... | @@ -6,15 +6,45 @@ const MODULE_NAME = 'KOMODO-SDK.SD-NOTIFY'; |
6 | 6 | const logger = require('tektrans-logger'); |
7 | 7 | const matrix = require('./matrix'); |
8 | 8 | |
9 | -module.exports = () => { | |
9 | +const notifyUseSdNotify = () => { | |
10 | 10 | try { |
11 | - const notify = require('sd-notify'); | |
11 | + const sdNotify = require('sd-notify'); | |
12 | 12 | |
13 | - notify.ready(); | |
13 | + sdNotify.ready(); | |
14 | 14 | matrix.systemd_notified = new Date(); |
15 | 15 | |
16 | - logger.info(`${MODULE_NAME} 701F8400: Systemd ready notification has been sent`); | |
16 | + logger.info(`${MODULE_NAME} 701F8400: Systemd ready notification has been sent using sd-notify module`); | |
17 | 17 | } catch (e) { |
18 | 18 | logger.warn(`${MODULE_NAME} A6C99938: Optional dependency not found: sd-notify`); |
19 | 19 | } |
20 | 20 | }; |
21 | + | |
22 | +/** | |
23 | + * | |
24 | + * @param {string} statusMsg | |
25 | + * @returns | |
26 | + */ | |
27 | +module.exports = async (statusMsg) => { | |
28 | + const { ppid } = process; | |
29 | + | |
30 | + if (ppid !== 1) { | |
31 | + logger.verbose(`${MODULE_NAME} 74A5B2AF: No need to notify systemd`, { ppid }); | |
32 | + return; | |
33 | + } | |
34 | + | |
35 | + try { | |
36 | + const notify = require('systemd-notify'); | |
37 | + | |
38 | + const status = statusMsg || 'Ready to go'; | |
39 | + | |
40 | + logger.verbose(`${MODULE_NAME} 3B8DF3BC: Trying to notify systemd using systemd-notify package`, { status }); | |
41 | + | |
42 | + await notify({ | |
43 | + ready: true, | |
44 | + status, | |
45 | + }); | |
46 | + } catch (e) { | |
47 | + logger.verbose(`${MODULE_NAME} 488B3245: Trying to notify sd-notify package`); | |
48 | + notifyUseSdNotify(); | |
49 | + } | |
50 | +}; |