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
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var spawn = require('child_process').spawn,
|
var pm2 = require('pm2'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
logo = fs.readFileSync(path.join(__dirname,'logo.txt'), 'utf8'),
|
logo = fs.readFileSync(path.join(__dirname,'logo.txt'), 'utf8'),
|
||||||
cli = require('commander'),
|
cli = require('commander'),
|
||||||
package = require('./package.json');
|
package = require('./package.json');
|
||||||
|
|
||||||
|
|
||||||
function start() {
|
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(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() {
|
function stop() {
|
||||||
|
|
||||||
var child = spawn('sudo', ['forever-service', 'delete', 'xcarve'], {
|
pm2.connect((err) => {
|
||||||
cwd: __dirname,
|
|
||||||
env: process.env,
|
if(err) {
|
||||||
detached: true
|
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);
|
cli.version(package.version);
|
||||||
|
|
@ -45,4 +57,3 @@ cli.parse(process.argv);
|
||||||
if (!process.argv.slice(2).length) {
|
if (!process.argv.slice(2).length) {
|
||||||
cli.outputHelp();
|
cli.outputHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
18
package.json
18
package.json
|
|
@ -1,8 +1,14 @@
|
||||||
{
|
{
|
||||||
"name": "xcarve-server",
|
"name": "xcarve-server",
|
||||||
"version": "1.0.11",
|
"version": "1.1.0",
|
||||||
"bin": "./cli",
|
"bin": "./cli",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"iris": {
|
||||||
|
"abilities": {
|
||||||
|
"detectPorts": true,
|
||||||
|
"zProbe": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/adafruit/xcarve-server"
|
"url": "https://github.com/adafruit/xcarve-server"
|
||||||
|
|
@ -19,10 +25,10 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/adafruit/xcarve-server",
|
"homepage": "https://github.com/adafruit/xcarve-server",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"commander": "^2.8.1",
|
"commander": "^2.9.0",
|
||||||
"onoff": "^1.0.2",
|
"onoff": "^1.1.1",
|
||||||
"serialport": "1.7.x",
|
"pm2": "^2.1.4",
|
||||||
"socket.io": "1.3.x",
|
"serialport": "^2.0.5",
|
||||||
"underscore": "1.4.x"
|
"socket.io": "^1.3.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue