-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
37 lines (34 loc) · 1.06 KB
/
index.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
import { spawn } from 'child_process';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { setupMaster, fork } from 'cluster';
try {
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
let running = false
function start() {
if (running) return
running = true
const args = [join(__dirname, 'main.js'), ...process.argv.slice(2)];
setupMaster({ exec: args[0], args: args.slice(1) });
const p = fork()
.on('message', (msg) => {
console.log(msg)
})
.on('error', (error) => {
console.error('Error occurred in the child process:', error);
})
.on('exit', (code, signal) => {
console.error(`Child process exited with code: ${code}, signal: ${signal}`);
})
.on('disconnect', () => {
console.log('Child process disconnected');
})
.on('polling_error', (error) => {
console.error('Polling error:', error);
});
}
start()
} catch (error){
console.log(error)
}