1
- /* eslint-disable no-console */
2
-
3
1
"use strict" ;
4
2
5
- const
6
- os = require ( "os" ) ,
3
+ const os = require ( "os" ) ,
7
4
cluster = require ( "cluster" ) ,
8
5
stopSignals = [
9
- "SIGHUP" , "SIGINT" , "SIGQUIT" , "SIGILL" , "SIGTRAP" , "SIGABRT" ,
10
- "SIGBUS" , "SIGFPE" , "SIGUSR1" , "SIGSEGV" , "SIGUSR2" , "SIGTERM"
6
+ "SIGHUP" ,
7
+ "SIGINT" ,
8
+ "SIGQUIT" ,
9
+ "SIGILL" ,
10
+ "SIGTRAP" ,
11
+ "SIGABRT" ,
12
+ "SIGBUS" ,
13
+ "SIGFPE" ,
14
+ "SIGUSR1" ,
15
+ "SIGSEGV" ,
16
+ "SIGUSR2" ,
17
+ "SIGTERM"
11
18
] ,
12
19
production = true ; //process.env.NODE_ENV == "production";
13
20
14
21
let stopping = false ;
15
22
16
- cluster . on ( "disconnect" , function ( worker ) {
23
+ cluster . on ( "disconnect" , function ( worker ) {
17
24
if ( production ) {
18
25
if ( ! stopping ) {
19
26
cluster . fork ( ) ;
20
27
}
21
- } else
22
- process . exit ( 1 ) ;
28
+ } else process . exit ( 1 ) ;
23
29
} ) ;
24
30
25
31
if ( cluster . isMaster ) {
@@ -30,11 +36,11 @@ if (cluster.isMaster) {
30
36
}
31
37
32
38
if ( production ) {
33
- stopSignals . forEach ( function ( signal ) {
34
- process . on ( signal , function ( ) {
39
+ stopSignals . forEach ( function ( signal ) {
40
+ process . on ( signal , function ( ) {
35
41
console . log ( `Got ${ signal } , stopping workers...` ) ;
36
42
stopping = true ;
37
- cluster . disconnect ( function ( ) {
43
+ cluster . disconnect ( function ( ) {
38
44
console . log ( "All workers stopped, exiting." ) ;
39
45
process . exit ( 0 ) ;
40
46
} ) ;
@@ -48,7 +54,6 @@ if (cluster.isMaster) {
48
54
worker . process . argv . push ( hostname + "-worker-" + worker . id ) ;
49
55
50
56
require ( "./worker.js" ) ;
51
-
52
57
}
53
58
54
59
/**
0 commit comments