xcarve-server/cli
2015-08-17 16:44:24 -04:00

48 lines
1.1 KiB
JavaScript
Executable file

#!/usr/bin/env node
var spawn = require('child_process').spawn,
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...');
child.on('error', console.log);
}
function stop() {
var child = spawn('sudo', ['forever-service', 'delete', 'xcarve'], {
cwd: __dirname,
env: process.env,
detached: true
});
console.log('stopping service...');
child.on('error', console.log);
}
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();
}