This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathksapi
executable file
·70 lines (63 loc) · 1.84 KB
/
ksapi
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
#!/usr/bin/env node
// vim: ft=javascript
args = process.argv.slice(2);
var arg = (args.length == 0) ? "start" : args[0];
console.log(arg);
var pm2d = require('./libs/pm2d');
switch(arg) {
case 'start':
console.log('satrting');
start(); break;
//case 'reload':
//reload(); break;
//case 'kill':
//kill();break;
//case 'list':
//list();break;
//case 'desc':
//describe(args[1]);break;
case 'exit':
case 'kill':
kill(); break;
}
function start() {
app = {
script: "./bin/www",
options: {
name: "ksapi",
executeCommand: true
}
};
pm2d.connect().then(function (res) {
console.log('KSAPI: connected to PM2 daemon, preparing to start application');
return pm2d.start(app);
}).then(function (res) {
console.log('KSAPI: server instance started');
}, function (res) {
err_msg = 'KSAPI: failed to start server instance, error: ["'+ res.error +'"]';
if (res.extra) {
err_msg += ', details: ' + JSON.stringify(res.extra);
}
console.log(err_msg);
}).fin(function (res) {
console.log('KSAPI: disconnecting from PM2 daemon');
return pm2d.disconnect().fin(exit);
});
}
function kill() {
pm2d.connect().then(function (res) {
console.log('KSAPI: connected to PM2 daemon, preparing to terminate');
return pm2d.kill();
}).then(function (res) {
console.log('KSAPI: PM2 datemon terminated');
}, function (res) {
console.log(JSON.stringify(res));
console.log('KSAPI: failed to terminate PM2 daemon, disconnecting');
return pm2d.disconnect();
}).fin(exit);
}
function exit(n) {
console.log('KSAPI: exit process');
if (typeof n === 'undefined') { n = 0; }
return process.exit(n);
}