-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-daemon.js
More file actions
executable file
·48 lines (37 loc) · 1.14 KB
/
Copy pathstart-daemon.js
File metadata and controls
executable file
·48 lines (37 loc) · 1.14 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
#!/usr/bin/env node
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
function startDaemon() {
const pidFile = path.join(process.cwd(), 'helios-backups.pid');
if (fs.existsSync(pidFile)) {
const existingPid = fs.readFileSync(pidFile, 'utf8').trim();
try {
process.kill(parseInt(existingPid), 0);
console.error('[ERROR] Daemon already running with PID:', existingPid);
process.exit(1);
} catch (error) {
fs.unlinkSync(pidFile);
}
}
const daemonPath = path.resolve(__dirname, 'dist', 'daemon.js');
console.log(`[INFO] Starting daemon from: ${daemonPath}`);
const child = spawn(process.argv[0], [daemonPath], {
detached: true,
stdio: 'ignore',
env: {
...process.env,
NODE_ENV: 'production',
HELIOS_DAEMON: 'true'
}
});
child.unref();
if (!child.pid) {
console.error('[ERROR] Failed to start daemon process');
process.exit(1);
}
fs.writeFileSync(pidFile, child.pid.toString());
console.log(`[INFO] Daemon started successfully with PID: ${child.pid}`);
process.exit(0);
}
startDaemon();