-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices.js
38 lines (28 loc) · 1.17 KB
/
services.js
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
const util = require("util");
const { exec } = require("child_process");
const execPromise = util.promisify(exec);
const UNKNOWN = "unknown";
async function getServiceStatus() {
const [ pocketncStatus, rockhopperStatus ] = await Promise.all([ execPromise("systemctl status PocketNC"),
execPromise("systemctl status Rockhopper") ]);
const {
stdout: pocketncStdout
} = pocketncStatus;
const {
stdout: rockhopperStdout
} = rockhopperStatus;
const pocketncLines = pocketncStdout.trim().split('\n').map((str) => str.trim());
const rockhopperLines = rockhopperStdout.trim().split('\n').map((str) => str.trim());
const pocketnc = pocketncLines.find((line) => line.startsWith("Active")).split(" ")[1] || UNKNOWN;
const rockhopper = pocketncLines.find((line) => line.startsWith("Active")).split(" ")[1] || UNKNOWN;
return { pocketnc, rockhopper };
}
async function shutdownServices() {
await Promise.all([ execPromise("sudo systemctl stop PocketNC"),
execPromise("sudo systemctl stop Rockhopper") ]);
return { shutdown: true };
}
module.exports = {
getServiceStatus,
shutdownServices
};