forked from xiaolulu/upopen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launcher.js
154 lines (142 loc) · 4.79 KB
/
launcher.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
var _ = require('underscore');
var pm2 = require('pm2');
var pmid = process.env.pm_id;
var settings = require('./common/settings');
require('./common/msg').contact('launcher', pmid, {
contact : function( data, res ){
console.log(data.name+'-'+data.pmid+' started');
res();
}
});
// ================================================================================
// server start
// ================================================================================
var serverList = {
'data' : {
"name" : "data",
"script" : "product/server/process/data/master.js",
"log_date_format" : "YYYY-MM-DD HH:mm:ss",
"out_file" : "./logs/data_out.log",
"error_file" : "./logs/data_err.log",
"log_file" : "./logs/data_log.log"
},
'account' : {
"name" : "account",
"script" : "./product/server/process/account/master.js",
"log_date_format" : "YYYY-MM-DD HH:mm:ss",
"out_file" : "./logs/account_out.log",
"error_file" : "./logs/account_err.log",
"log_file" : "./logs/account_log.log"
},
'purview' : {
"name" : "purview",
"script" : "./product/server/process/purview/master.js",
"out_file" : "./logs/purview_out.log",
"error_file" : "./logs/purview_err.log",
"log_file" : "./logs/purview_log.log"
},
'socket' : {
"name" : "socket",
"script" : "./product/server/process/socket/master.js",
"log_date_format" : "YYYY-MM-DD HH:mm:ss",
"out_file" : "./logs/socket_out.log",
"error_file" : "./logs/socket_err.log",
"log_file" : "./logs/socket_log.log"
},
'task' : {
"name" : "task",
"script" : "./product/server/process/task/master.js",
"log_date_format" : "YYYY-MM-DD HH:mm:ss",
"out_file" : "./logs/task_out.log",
"error_file" : "./logs/task_err.log",
"log_file" : "./logs/task_log.log"
},
'vm' : {
"name" : "vm",
"script" : "./product/server/process/vm/master.js",
"log_date_format" : "YYYY-MM-DD HH:mm:ss",
"exec_mode" : "cluster",
"instances" : 1,
"out_file" : "./logs/vm_out.log",
"error_file" : "./logs/vm_err.log",
"log_file" : "./logs/vm_log.log",
"max_memory_restart" : "500M"
},
'vm-dc' : {
"name" : "vm-dc",
"script" : "./product/server/process/vm/master.js",
"log_date_format" : "YYYY-MM-DD HH:mm:ss",
"exec_mode" : "cluster",
"instances" : 1,
"out_file" : "./logs/vm-dc_out.log",
"error_file" : "./logs/vm-dc_err.log",
"log_file" : "./logs/vm-dc_log.log",
"node_args" : "--max-old-space-size=150"
},
'api' : {
"name" : "api",
"script" : "./product/server/process/api/master.js",
"log_date_format" : "YYYY-MM-DD HH:mm:ss",
"exec_mode" : "cluster",
"instances" : 1,
"out_file" : "./logs/api_out.log",
"error_file" : "./logs/api_err.log",
"log_file" : "./logs/api_log.log",
"node_args" : "--max-old-space-size=150 --harmony"
},
'web' : {
"name" : "web",
"script" : "./product/server/process/web/master.js",
"log_date_format" : "YYYY-MM-DD HH:mm:ss",
"exec_mode" : "cluster",
"instances" : 1,
"out_file" : "./logs/web_out.log",
"error_file" : "./logs/web_err.log",
"log_file" : "./logs/web_log.log",
"node_args" : "--harmony",
"max_memory_restart" : "300M"
},
'open' : {
"name" : "open",
"script" : "./product/server/process/open/master.js",
"log_date_format" : "YYYY-MM-DD HH:mm:ss",
"exec_mode" : "cluster",
"instances" : 1,
"out_file" : "./logs/open_out.log",
"error_file" : "./logs/open_err.log",
"log_file" : "./logs/open_log.log",
"node_args" : "--harmony",
"max_memory_restart" : "1200M"
}
};
// ================================================================================
// start
// ================================================================================
var start = function(){
console.log('>>>>>>>>>> NEREUS <<<<<<<<<<');
console.log('Launch services...');
// 连接pm2
pm2.connect(function(){
var already = [], serverKeys = _.keys(serverList);
var startOne = function( key ) {
if ( key === undefined ) {return;}
console.log(`launch ${key}`);
if ( already.indexOf(key) === -1 ) {
pm2.start( serverList[key], function(){
startOne(serverKeys.shift());
});
} else {
pm2.restart(key, function(){
startOne(serverKeys.shift());
});
}
};
pm2.list(function(err, list){
_.each(list, (app)=>{
already.push(app.name);
});
startOne(serverKeys.shift());
});
});
};
start();