forked from oxen-io/lokinet-gui
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlokinetProcessManagerSystemd.ts
More file actions
48 lines (41 loc) · 1.47 KB
/
lokinetProcessManagerSystemd.ts
File metadata and controls
48 lines (41 loc) · 1.47 KB
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
39
40
41
42
43
44
45
46
47
48
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ILokinetProcessManager, invoke } from './lokinetProcessManager';
import util from 'util';
import { exec } from 'child_process';
import { logLineToAppSide } from './ipcNode';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const execPromisified = util.promisify(exec);
export const isSystemD = async (): Promise<boolean> => {
try {
const { stdout, stderr } = await execPromisified(
'ps --no-headers -o comm 1'
);
if (stdout && stdout.trim() === 'systemd') {
logLineToAppSide('SystemD: The current system is using systemd.');
return true;
}
console.log('isSystemD stderr:', stderr);
throw new Error('not systemD');
} catch (e: any) {
logLineToAppSide(`The current system is NOT using systemd: ${e.message}`);
console.error(e); // should contain code (exit code) and signal (that caused the termination).
return false;
}
};
const lokinetService = 'lokinet.service';
export class LokinetSystemDProcessManager implements ILokinetProcessManager {
async nodeStartLokinetProcess(): Promise<string | null> {
const result = await invoke('systemctl', [
'--no-block',
'start',
lokinetService
]);
if (!result) {
logLineToAppSide('SystemD: lokinet service started');
}
return result;
}
async nodeStopLokinetProcess(): Promise<string | null> {
return invoke('systemctl', ['--no-block', 'stop', lokinetService]);
}
}