adds start & stop command line args

This commit is contained in:
Todd Treece 2015-08-17 10:42:37 -04:00
parent b7f4b1e0c3
commit c165aca080
2 changed files with 52 additions and 10 deletions

38
cli
View file

@ -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);

View file

@ -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",