]>
git.r.bdr.sh - rbdr/monitorcito/blob - lib/index.js
1 const { promisify
} = require('util');
2 const { exec
} = require('child_process');
5 kActiveIndicator: 'active',
7 kKeyValueSeparator: '=',
8 kBlockSeparator: '\n\n',
9 statusCommand: 'systemctl show --no-page -p Id -p ActiveState',
11 formatStatusOutput(systemctlText
) {
13 const blocks
= systemctlText
.trim().split(internals
.kBlockSeparator
);
17 const fields
= block
.split(internals
.kFieldSeparator
);
18 return fields
.reduce((fieldObject
, field
) => {
20 const [key
, value
] = field
.split(internals
.kKeyValueSeparator
);
28 .reduce((statusObject
, service
) => {
32 [service
.Id
]: service
.ActiveState
=== internals
.kActiveIndicator
40 module
.exports
= async (services
) => {
42 const { stdout
} = await internals
.exec(`${internals.statusCommand} ${services.join(' ')}`);
43 return internals
.formatStatusOutput(stdout
);