adds start & stop command line args
This commit is contained in:
parent
b7f4b1e0c3
commit
c165aca080
2 changed files with 52 additions and 10 deletions
40
cli
40
cli
|
|
@ -1,18 +1,44 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var child,
|
||||
spawn = require('child_process').spawn,
|
||||
var spawn = require('child_process').spawn,
|
||||
fs = require('fs'),
|
||||
path = require('path');
|
||||
path = require('path'),
|
||||
logo = fs.readFileSync(path.join(__dirname,'logo.txt'), 'utf8'),
|
||||
cli = require('commander'),
|
||||
package = require('./package.json'),
|
||||
child;
|
||||
|
||||
var logo = fs.readFileSync(path.join(__dirname,'logo.txt'), 'utf8');
|
||||
cli
|
||||
.version(package.version)
|
||||
.command('start', 'installs and starts the service')
|
||||
.command('stop', 'stops and removes the service')
|
||||
.parse(process.argv);
|
||||
|
||||
console.log(logo);
|
||||
if(cli.start) {
|
||||
|
||||
child = spawn('forever', ['start', 'index.js', '-s'], {
|
||||
child = spawn('sudo forever-service', ['install', '-s index.js', '--start', '--runAsUser pi'], {
|
||||
cwd: __dirname,
|
||||
env: process.env,
|
||||
detached: true
|
||||
});
|
||||
});
|
||||
|
||||
console.log(logo);
|
||||
console.log('starting service on port 1338...');
|
||||
|
||||
} else if (cli.stop) {
|
||||
|
||||
child = spawn('sudo forever-service', ['delete', 'index.js'], {
|
||||
cwd: __dirname,
|
||||
env: process.env,
|
||||
detached: true
|
||||
});
|
||||
console.log('stopping service...');
|
||||
|
||||
} else {
|
||||
|
||||
cli.outputHelp();
|
||||
|
||||
}
|
||||
|
||||
child.on('error', console.log);
|
||||
|
||||
|
|
|
|||
16
package.json
16
package.json
|
|
@ -3,7 +3,23 @@
|
|||
"version": "0.1.2",
|
||||
"bin": "./cli",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/adafruit/xcarve-server"
|
||||
},
|
||||
"keywords": [
|
||||
"adafruit",
|
||||
"xcarve",
|
||||
"inventables",
|
||||
"raspberry pi"
|
||||
],
|
||||
"author": "Todd Treece <todd@uniontownlabs.org>",
|
||||
"bugs": {
|
||||
"url": "https://github.com/adafruit/xcarve-server/issues"
|
||||
},
|
||||
"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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue