forked from adafruit/xcarve-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli
executable file
·60 lines (45 loc) · 1.12 KB
/
cli
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
#!/usr/bin/env node
var pm2 = require('pm2'),
fs = require('fs'),
path = require('path'),
logo = fs.readFileSync(path.join(__dirname,'logo.txt'), 'utf8'),
cli = require('commander'),
package = require('./package.json');
function start() {
console.log(logo);
pm2.connect((err) => {
if(err) {
console.error(err);
process.exit(2);
}
pm2.start({
script: 'index.js',
name: 'xcarve',
cwd: process.cwd()
}, (err, apps) => {
pm2.disconnect();
if (err) throw err
console.log('starting server on port 1338...\n');
});
});
}
function stop() {
pm2.connect((err) => {
if(err) {
console.error(err);
process.exit(2);
}
pm2.stop('xcarve', (err) => {
if(err) throw err;
console.log('stopping service...');
process.exit();
});
});
}
cli.version(package.version);
cli.command('start').description('installs and starts the service').action(start);
cli.command('stop').description('stops and removes the service').action(stop);
cli.parse(process.argv);
if (!process.argv.slice(2).length) {
cli.outputHelp();
}