forked from NetEase/pomelo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpomelo
executable file
·681 lines (638 loc) · 21.5 KB
/
pomelo
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
#!/usr/bin/env node
/**
* Module dependencies.
*/
var fs = require('fs'),
os = require('os'),
path = require('path'),
util = require('util'),
cliff = require('cliff'),
mkdirp = require('mkdirp'),
co = require('../lib/modules/console'),
utils = require('../lib/util/utils'),
starter = require('../lib/master/starter'),
exec = require('child_process').exec,
spawn = require('child_process').spawn,
version = require('../package.json').version,
adminClient = require('pomelo-admin').adminClient,
constants = require('../lib/util/constants'),
program = require('commander');
/**
* Constant Variables
*/
var TIME_INIT = 1 * 1000;
var TIME_KILL_WAIT = 5 * 1000;
var KILL_CMD_LUX = 'kill -9 `ps -ef|grep node|awk \'{print $2}\'`';
var KILL_CMD_WIN = 'taskkill /im node.exe /f';
var CUR_DIR = process.cwd();
var DEFAULT_GAME_SERVER_DIR = CUR_DIR;
var DEFAULT_USERNAME = 'admin';
var DEFAULT_PWD = 'admin';
var DEFAULT_ENV = 'development';
var DEFAULT_MASTER_HOST = '127.0.0.1';
var DEFAULT_MASTER_PORT = 3005;
var CONNECT_ERROR = 'Fail to connect to admin console server.';
var FILEREAD_ERROR = 'Fail to read the file, please check if the application is started legally.';
var CLOSEAPP_INFO = 'Closing the application......\nPlease wait......';
var ADD_SERVER_INFO = 'Successfully add server.';
var RESTART_SERVER_INFO = 'Successfully restart server.';
var INIT_PROJ_NOTICE = '\nThe default admin user is: \n\n'+ ' username'.green + ': admin\n ' + 'password'.green+ ': admin\n\nYou can configure admin users by editing adminUser.json later.\n ';
var SCRIPT_NOT_FOUND = 'Fail to find an appropriate script to run,\nplease check the current work directory or the directory specified by option `--directory`.\n'.red;
var MASTER_HA_NOT_FOUND = 'Fail to find an appropriate masterha config file, \nplease check the current work directory or the arguments passed to.\n'.red;
var COMMAND_ERROR = 'Illegal command format. Use `pomelo --help` to get more info.\n'.red;
var DAEMON_INFO = 'The application is running in the background now.\n';
program.version(version);
program.command('init [path]')
.description('create a new application')
.action(function(path) {
init(path || CUR_DIR);
});
program.command('start')
.description('start the application')
.option('-e, --env <env>', 'the used environment', DEFAULT_ENV)
.option('-D, --daemon', 'enable the daemon start')
.option('-d, --directory, <directory>', 'the code directory', DEFAULT_GAME_SERVER_DIR)
.option('-t, --type <server-type>,', 'start server type')
.option('-i, --id <server-id>', 'start server id')
.action(function(opts) {
start(opts);
});
program.command('list')
.description('list the servers')
.option('-u, --username <username>', 'administration user name', DEFAULT_USERNAME)
.option('-p, --password <password>', 'administration password', DEFAULT_PWD)
.option('-h, --host <master-host>', 'master server host', DEFAULT_MASTER_HOST)
.option('-P, --port <master-port>', 'master server port', DEFAULT_MASTER_PORT)
.action(function(opts) {
list(opts);
});
program.command('add')
.description('add a new server')
.option('-u, --username <username>', 'administration user name', DEFAULT_USERNAME)
.option('-p, --password <password>', 'administration password', DEFAULT_PWD)
.option('-h, --host <master-host>', 'master server host', DEFAULT_MASTER_HOST)
.option('-P, --port <master-port>', 'master server port', DEFAULT_MASTER_PORT)
.action(function() {
var args = [].slice.call(arguments, 0);
var opts = args[args.length - 1];
opts.args = args.slice(0, -1);
add(opts);
});
program.command('stop')
.description('stop the servers, for multiple servers, use `pomelo stop server-id-1 server-id-2`')
.option('-u, --username <username>', 'administration user name', DEFAULT_USERNAME)
.option('-p, --password <password>', 'administration password', DEFAULT_PWD)
.option('-h, --host <master-host>', 'master server host', DEFAULT_MASTER_HOST)
.option('-P, --port <master-port>', 'master server port', DEFAULT_MASTER_PORT)
.action(function() {
var args = [].slice.call(arguments, 0);
var opts = args[args.length - 1];
opts.serverIds = args.slice(0, -1);
terminal('stop', opts);
});
program.command('kill')
.description('kill the application')
.option('-u, --username <username>', 'administration user name', DEFAULT_USERNAME)
.option('-p, --password <password>', 'administration password', DEFAULT_PWD)
.option('-h, --host <master-host>', 'master server host', DEFAULT_MASTER_HOST)
.option('-P, --port <master-port>', 'master server port', DEFAULT_MASTER_PORT)
.option('-f, --force', 'using this option would kill all the node processes')
.action(function() {
var args = [].slice.call(arguments, 0);
var opts = args[args.length - 1];
opts.serverIds = args.slice(0, -1);
terminal('kill', opts);
});
program.command('restart')
.description('restart the servers, for multiple servers, use `pomelo restart server-id-1 server-id-2`')
.option('-u, --username <username>', 'administration user name', DEFAULT_USERNAME)
.option('-p, --password <password>', 'administration password', DEFAULT_PWD)
.option('-h, --host <master-host>', 'master server host', DEFAULT_MASTER_HOST)
.option('-P, --port <master-port>', 'master server port', DEFAULT_MASTER_PORT)
.option('-t, --type <server-type>,', 'start server type')
.option('-i, --id <server-id>', 'start server id')
.action(function(opts) {
restart(opts);
});
program.command('masterha')
.description('start all the slaves of the master')
.option('-d, --directory <directory>', 'the code directory', DEFAULT_GAME_SERVER_DIR)
.action(function(opts) {
startMasterha(opts);
});
program.command('*')
.action(function() {
console.log(COMMAND_ERROR);
});
program.parse(process.argv);
/**
* Init application at the given directory `path`.
*
* @param {String} path
*/
function init(path) {
console.log(INIT_PROJ_NOTICE);
connectorType(function(type) {
emptyDirectory(path, function(empty) {
if(empty) {
process.stdin.destroy();
createApplicationAt(path, type);
} else {
confirm('Destination is not empty, continue? (y/n) [no] ', function(force) {
process.stdin.destroy();
if(force) {
createApplicationAt(path, type);
} else {
abort('Fail to init a project'.red);
}
});
}
});
});
}
/**
* Create directory and files at the given directory `path`.
*
* @param {String} ph
*/
function createApplicationAt(ph, type) {
var name = path.basename(path.resolve(CUR_DIR, ph));
copy(path.join(__dirname, '../template/'), ph);
mkdir(path.join(ph, 'game-server/logs'));
mkdir(path.join(ph, 'shared'));
// rmdir -r
var rmdir = function(dir) {
var list = fs.readdirSync(dir);
for(var i = 0; i < list.length; i++) {
var filename = path.join(dir, list[i]);
var stat = fs.statSync(filename);
if(filename === "." || filename === "..") {
} else if(stat.isDirectory()) {
rmdir(filename);
} else {
fs.unlinkSync(filename);
}
}
fs.rmdirSync(dir);
};
setTimeout(function() {
switch(type) {
case '1':
// use websocket
var unlinkFiles = ['game-server/app.js.sio',
'game-server/app.js.wss',
'game-server/app.js.mqtt',
'game-server/app.js.sio.wss',
'game-server/app.js.udp',
'web-server/app.js.https',
'web-server/public/index.html.sio',
'web-server/public/js/lib/pomeloclient.js',
'web-server/public/js/lib/pomeloclient.js.wss',
'web-server/public/js/lib/build/build.js.wss',
'web-server/public/js/lib/socket.io.js'];
for(var i = 0; i < unlinkFiles.length; ++i) {
fs.unlinkSync(path.resolve(ph, unlinkFiles[i]));
}
break;
case '2':
// use socket.io
var unlinkFiles = ['game-server/app.js',
'game-server/app.js.wss',
'game-server/app.js.udp',
'game-server/app.js.mqtt',
'game-server/app.js.sio.wss',
'web-server/app.js.https',
'web-server/public/index.html',
'web-server/public/js/lib/component.json',
'web-server/public/js/lib/pomeloclient.js.wss'];
for(var i = 0; i < unlinkFiles.length; ++i) {
fs.unlinkSync(path.resolve(ph, unlinkFiles[i]));
}
fs.renameSync(path.resolve(ph, 'game-server/app.js.sio'), path.resolve(ph, 'game-server/app.js'));
fs.renameSync(path.resolve(ph, 'web-server/public/index.html.sio'), path.resolve(ph, 'web-server/public/index.html'));
rmdir(path.resolve(ph, 'web-server/public/js/lib/build'));
rmdir(path.resolve(ph, 'web-server/public/js/lib/local'));
break;
case '3':
// use websocket wss
var unlinkFiles = ['game-server/app.js.sio',
'game-server/app.js',
'game-server/app.js.udp',
'game-server/app.js.sio.wss',
'game-server/app.js.mqtt',
'web-server/app.js',
'web-server/public/index.html.sio',
'web-server/public/js/lib/pomeloclient.js',
'web-server/public/js/lib/pomeloclient.js.wss',
'web-server/public/js/lib/build/build.js',
'web-server/public/js/lib/socket.io.js'];
for(var i = 0; i < unlinkFiles.length; ++i) {
fs.unlinkSync(path.resolve(ph, unlinkFiles[i]));
}
fs.renameSync(path.resolve(ph, 'game-server/app.js.wss'), path.resolve(ph, 'game-server/app.js'));
fs.renameSync(path.resolve(ph, 'web-server/app.js.https'), path.resolve(ph, 'web-server/app.js'));
fs.renameSync(path.resolve(ph, 'web-server/public/js/lib/build/build.js.wss'), path.resolve(ph, 'web-server/public/js/lib/build/build.js'));
break;
case '4':
// use socket.io wss
var unlinkFiles = ['game-server/app.js.sio',
'game-server/app.js',
'game-server/app.js.udp',
'game-server/app.js.wss',
'game-server/app.js.mqtt',
'web-server/app.js',
'web-server/public/index.html',
'web-server/public/js/lib/pomeloclient.js'];
for(var i = 0; i < unlinkFiles.length; ++i) {
fs.unlinkSync(path.resolve(ph, unlinkFiles[i]));
}
fs.renameSync(path.resolve(ph, 'game-server/app.js.sio.wss'), path.resolve(ph, 'game-server/app.js'));
fs.renameSync(path.resolve(ph, 'web-server/app.js.https'), path.resolve(ph, 'web-server/app.js'));
fs.renameSync(path.resolve(ph, 'web-server/public/index.html.sio'), path.resolve(ph, 'web-server/public/index.html'));
fs.renameSync(path.resolve(ph, 'web-server/public/js/lib/pomeloclient.js.wss'), path.resolve(ph, 'web-server/public/js/lib/pomeloclient.js'));
rmdir(path.resolve(ph, 'web-server/public/js/lib/build'));
rmdir(path.resolve(ph, 'web-server/public/js/lib/local'));
fs.unlinkSync(path.resolve(ph, 'web-server/public/js/lib/component.json'));
break;
case '5':
// use socket.io wss
var unlinkFiles = ['game-server/app.js.sio',
'game-server/app.js',
'game-server/app.js.wss',
'game-server/app.js.mqtt',
'game-server/app.js.sio.wss',
'web-server/app.js.https',
'web-server/public/index.html',
'web-server/public/js/lib/component.json',
'web-server/public/js/lib/pomeloclient.js.wss'];
for(var i = 0; i < unlinkFiles.length; ++i) {
fs.unlinkSync(path.resolve(ph, unlinkFiles[i]));
}
fs.renameSync(path.resolve(ph, 'game-server/app.js.udp'), path.resolve(ph, 'game-server/app.js'));
rmdir(path.resolve(ph, 'web-server/public/js/lib/build'));
rmdir(path.resolve(ph, 'web-server/public/js/lib/local'));
break;
case '6':
// use socket.io
var unlinkFiles = ['game-server/app.js',
'game-server/app.js.wss',
'game-server/app.js.udp',
'game-server/app.js.sio',
'game-server/app.js.sio.wss',
'web-server/app.js.https',
'web-server/public/index.html',
'web-server/public/js/lib/component.json',
'web-server/public/js/lib/pomeloclient.js.wss'];
for(var i = 0; i < unlinkFiles.length; ++i) {
fs.unlinkSync(path.resolve(ph, unlinkFiles[i]));
}
fs.renameSync(path.resolve(ph, 'game-server/app.js.mqtt'), path.resolve(ph, 'game-server/app.js'));
fs.renameSync(path.resolve(ph, 'web-server/public/index.html.sio'), path.resolve(ph, 'web-server/public/index.html'));
rmdir(path.resolve(ph, 'web-server/public/js/lib/build'));
rmdir(path.resolve(ph, 'web-server/public/js/lib/local'));
break;
}
var replaceFiles = ['game-server/app.js',
'game-server/package.json',
'web-server/package.json'];
for(var j = 0; j < replaceFiles.length; j++) {
var str = fs.readFileSync(path.resolve(ph, replaceFiles[j])).toString();
fs.writeFileSync(path.resolve(ph, replaceFiles[j]), str.replace('$', name));
}
var f = path.resolve(ph, 'game-server/package.json');
var content = fs.readFileSync(f).toString();
fs.writeFileSync(f, content.replace('#', version));
}, TIME_INIT);
}
/**
* Start application.
*
* @param {Object} opts options for `start` operation
*/
function start(opts) {
var absScript = path.resolve(opts.directory, 'app.js');
if (!fs.existsSync(absScript)) {
abort(SCRIPT_NOT_FOUND);
}
var logDir = path.resolve(opts.directory, 'logs');
if (!fs.existsSync(logDir)) {
fs.mkdir(logDir);
}
var ls;
var type = opts.type || constants.RESERVED.ALL;
var params = [absScript, 'env=' + opts.env, 'type=' + type];
if(!!opts.id) {
params.push('startId=' + opts.id);
}
if (opts.daemon) {
ls = spawn(process.execPath, params, {detached: true, stdio: 'ignore'});
ls.unref();
console.log(DAEMON_INFO);
process.exit(0);
} else {
ls = spawn(process.execPath, params);
ls.stdout.on('data', function(data) {
console.log(data.toString());
});
ls.stderr.on('data', function(data) {
console.log(data.toString());
});
}
}
/**
* List pomelo processes.
*
* @param {Object} opts options for `list` operation
*/
function list(opts) {
var id = 'pomelo_list_' + Date.now();
connectToMaster(id, opts, function(client) {
client.request(co.moduleId, {signal: 'list'}, function(err, data) {
if(err) {
console.error(err);
}
var servers = [];
for(var key in data.msg) {
servers.push(data.msg[key]);
}
var comparer = function(a, b) {
if (a.serverType < b.serverType) {
return -1;
} else if (a.serverType > b.serverType) {
return 1;
} else if (a.serverId < b.serverId) {
return -1;
} else if (a.serverId > b.serverId) {
return 1;
} else {
return 0;
}
};
servers.sort(comparer);
var rows = [];
rows.push(['serverId', 'serverType', 'pid', 'rss(M)', 'heapTotal(M)', 'heapUsed(M)', 'uptime(m)']);
servers.forEach(function(server) {
rows.push([server.serverId, server.serverType, server.pid, server.rss, server.heapTotal, server.heapUsed, server.uptime]);
});
console.log(cliff.stringifyRows(rows, ['red', 'blue', 'green', 'cyan', 'magenta', 'white', 'yellow']));
process.exit(0);
});
});
}
/**
* Add server to application.
*
* @param {Object} opts options for `add` operation
*/
function add(opts) {
var id = 'pomelo_add_' + Date.now();
connectToMaster(id, opts, function(client) {
client.request(co.moduleId, { signal: 'add', args: opts.args }, function(err) {
if(err) {
console.error(err);
}
else {
console.info(ADD_SERVER_INFO);
}
process.exit(0);
});
});
}
/**
* Terminal application.
*
* @param {String} signal stop/kill
* @param {Object} opts options for `stop/kill` operation
*/
function terminal(signal, opts) {
console.info(CLOSEAPP_INFO);
// option force just for `kill`
if(opts.force) {
if (os.platform() === constants.PLATFORM.WIN) {
exec(KILL_CMD_WIN);
} else {
exec(KILL_CMD_LUX);
}
process.exit(1);
return;
}
var id = 'pomelo_terminal_' + Date.now();
connectToMaster(id, opts, function(client) {
client.request(co.moduleId, {
signal: signal, ids: opts.serverIds
}, function(err, msg) {
if(err) {
console.error(err);
}
if(signal === 'kill') {
if(msg.code === 'ok') {
console.log('All the servers have been terminated!');
} else {
console.log('There may be some servers remained:', msg.serverIds);
}
}
process.exit(0);
});
});
}
function restart(opts) {
var id = 'pomelo_restart_' + Date.now();
var serverIds = [];
var type = null;
if(!!opts.id) {
serverIds.push(opts.id);
}
if(!!opts.type) {
type = opts.type;
}
connectToMaster(id, opts, function(client) {
client.request(co.moduleId, { signal: 'restart', ids: serverIds, type: type}, function(err, fails) {
if(!!err) {
console.error(err);
} else if(!!fails.length) {
console.info('restart fails server ids: %j', fails);
} else {
console.info(RESTART_SERVER_INFO);
}
process.exit(0);
});
});
}
function connectToMaster(id, opts, cb) {
var client = new adminClient({username: opts.username, password: opts.password, md5: true});
client.connect(id, opts.host, opts.port, function(err) {
if(err) {
abort(CONNECT_ERROR + err.red);
}
if(typeof cb === 'function') {
cb(client);
}
});
}
/**
* Start master slaves.
*
* @param {String} option for `startMasterha` operation
*/
function startMasterha(opts) {
var configFile = path.join(opts.directory, constants.FILEPATH.MASTER_HA);
if(!fs.existsSync(configFile)) {
abort(MASTER_HA_NOT_FOUND);
}
var masterha = require(configFile).masterha;
for(var i=0; i<masterha.length; i++) {
var server = masterha[i];
server.mode = constants.RESERVED.STAND_ALONE;
server.masterha = 'true';
server.home = opts.directory;
runServer(server);
}
}
/**
* Check if the given directory `path` is empty.
*
* @param {String} path
* @param {Function} fn
*/
function emptyDirectory(path, fn) {
fs.readdir(path, function(err, files) {
if(err && 'ENOENT' !== err.code) {
abort(FILEREAD_ERROR);
}
fn(!files || !files.length);
});
}
/**
* Prompt confirmation with the given `msg`.
*
* @param {String} msg
* @param {Function} fn
*/
function confirm(msg, fn) {
prompt(msg, function(val) {
fn(/^ *y(es)?/i.test(val));
});
}
/**
* Prompt input with the given `msg` and callback `fn`.
*
* @param {String} msg
* @param {Function} fn
*/
function prompt(msg, fn) {
if(' ' === msg[msg.length - 1]) {
process.stdout.write(msg);
} else {
console.log(msg);
}
process.stdin.setEncoding('ascii');
process.stdin.once('data', function(data) {
fn(data);
}).resume();
}
/**
* Exit with the given `str`.
*
* @param {String} str
*/
function abort(str) {
console.error(str);
process.exit(1);
}
/**
* Copy template files to project.
*
* @param {String} origin
* @param {String} target
*/
function copy(origin, target) {
if(!fs.existsSync(origin)) {
abort(origin + 'does not exist.');
}
if(!fs.existsSync(target)) {
mkdir(target);
console.log(' create : '.green + target);
}
fs.readdir(origin, function(err, datalist) {
if(err) {
abort(FILEREAD_ERROR);
}
for(var i = 0; i < datalist.length; i++) {
var oCurrent = path.resolve(origin, datalist[i]);
var tCurrent = path.resolve(target, datalist[i]);
if(fs.statSync(oCurrent).isFile()) {
fs.writeFileSync(tCurrent, fs.readFileSync(oCurrent, ''), '');
console.log(' create : '.green + tCurrent);
} else if(fs.statSync(oCurrent).isDirectory()) {
copy(oCurrent, tCurrent);
}
}
});
}
/**
* Mkdir -p.
*
* @param {String} path
* @param {Function} fn
*/
function mkdir(path, fn) {
mkdirp(path, 0755, function(err){
if(err) {
throw err;
}
console.log(' create : '.green + path);
if(typeof fn === 'function') {
fn();
}
});
}
/**
* Get user's choice on connector selecting
*
* @param {Function} cb
*/
function connectorType(cb) {
prompt('Please select underly connector, 1 for websocket(native socket), 2 for socket.io, 3 for wss, 4 for socket.io(wss), 5 for udp, 6 for mqtt: [1]', function(msg) {
switch(msg.trim()) {
case '':
cb(1);
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
cb(msg.trim());
break;
default:
console.log('Invalid choice! Please input 1 - 5.'.red + '\n');
connectorType(cb);
break;
}
});
}
/**
* Run server.
*
* @param {Object} server server information
*/
function runServer(server) {
var cmd, key;
var main = path.resolve(server.home, 'app.js');
if(utils.isLocal(server.host)) {
var options = [];
options.push(main);
for(key in server) {
options.push(util.format('%s=%s', key, server[key]));
}
starter.localrun(process.execPath, null, options);
} else {
cmd = util.format('cd "%s" && "%s"', server.home, process.execPath);
cmd += util.format(' "%s" ', main);
for(key in server) {
cmd += util.format(' %s=%s ', key, server[key]);
}
starter.sshrun(cmd, server.host);
}
}