move to pm2 from forvever-service
This commit is contained in:
parent
7b40f420e3
commit
11555141eb
2 changed files with 42 additions and 25 deletions
49
cli
49
cli
|
|
@ -1,40 +1,52 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var spawn = require('child_process').spawn,
|
||||
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() {
|
||||
|
||||
var child = spawn('sudo', ['forever-service', 'install', '-s', 'index.js', '--start', '--runAsUser', 'pi', 'xcarve'], {
|
||||
cwd: __dirname,
|
||||
env: process.env,
|
||||
detached: true
|
||||
});
|
||||
|
||||
console.log(logo);
|
||||
console.log('starting service on port 1338...');
|
||||
pm2.connect((err) => {
|
||||
|
||||
child.on('error', console.log);
|
||||
if(err) {
|
||||
console.error(err);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
pm2.start({
|
||||
script: 'index.js',
|
||||
name: 'xcarve'
|
||||
}, (err, apps) => {
|
||||
pm2.disconnect();
|
||||
if (err) throw err
|
||||
console.log('starting server on port 1338...\n');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function stop() {
|
||||
|
||||
var child = spawn('sudo', ['forever-service', 'delete', 'xcarve'], {
|
||||
cwd: __dirname,
|
||||
env: process.env,
|
||||
detached: true
|
||||
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();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
console.log('stopping service...');
|
||||
|
||||
child.on('error', console.log);
|
||||
|
||||
}
|
||||
|
||||
cli.version(package.version);
|
||||
|
|
@ -45,4 +57,3 @@ cli.parse(process.argv);
|
|||
if (!process.argv.slice(2).length) {
|
||||
cli.outputHelp();
|
||||
}
|
||||
|
||||
|
|
|
|||
18
package.json
18
package.json
|
|
@ -1,8 +1,14 @@
|
|||
{
|
||||
"name": "xcarve-server",
|
||||
"version": "1.0.11",
|
||||
"version": "1.1.0",
|
||||
"bin": "./cli",
|
||||
"license": "MIT",
|
||||
"iris": {
|
||||
"abilities": {
|
||||
"detectPorts": true,
|
||||
"zProbe": true
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/adafruit/xcarve-server"
|
||||
|
|
@ -19,10 +25,10 @@
|
|||
},
|
||||
"homepage": "https://github.com/adafruit/xcarve-server",
|
||||
"dependencies": {
|
||||
"commander": "^2.8.1",
|
||||
"onoff": "^1.0.2",
|
||||
"serialport": "1.7.x",
|
||||
"socket.io": "1.3.x",
|
||||
"underscore": "1.4.x"
|
||||
"commander": "^2.9.0",
|
||||
"onoff": "^1.1.1",
|
||||
"pm2": "^2.1.4",
|
||||
"serialport": "^2.0.5",
|
||||
"socket.io": "^1.3.7"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue