From 93053d64e7bd46e473ad455291dfe4dc4d5e74f4 Mon Sep 17 00:00:00 2001 From: bradleymeck Date: Tue, 20 Sep 2011 11:21:07 -0500 Subject: [PATCH] [api] Revive the service api stubs --- bin/forever | 1 + lib/forever/cli.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/bin/forever b/bin/forever index 2d4e92cb..f6dca6ad 100755 --- a/bin/forever +++ b/bin/forever @@ -12,6 +12,7 @@ var action, accepts = [ 'clear', 'columns', 'list', + 'service', 'start', 'stop', 'stopall', diff --git a/lib/forever/cli.js b/lib/forever/cli.js index 544dfa12..2f7e26ea 100644 --- a/lib/forever/cli.js +++ b/lib/forever/cli.js @@ -222,6 +222,65 @@ cli.clear = function (key) { }); }; +// +// ### function service(action) +// add +// install +// start +// stop +// restart +// +// TODO - guard against user invocation +// +cli.service = function (action) { + // + // Add descriptor to our service list + // this is just a json file in $root/services/*.json + // + if('add' == action) { + var service = options; + var file = path.join(forever.config.get('root'), 'services', options.uid + '.json'); + fs.writeFileSync(file, JSON.stringify(service)); + } + // + // Copy the init.d script to the right location + // TODO Distribution fixes? + // + if('install' == action) { + var service = options; + var script = fs.createReadStream(path.join(__dirname, '..', '..', 'init.d', 'forever-services')); + var target = fs.createWriteStream(path.join('/etc', 'init.d', 'forever-services')); + file.pipe(target); + } + // + // Start all of the scripts + // + if('start' == action) { + var serviceFiles = readdirSync(path.join(forever.config.get('root'), 'services')); + serviceFiles.forEach(function(serviceFile) { + forever.start(fs.readFileSync(serviceFile)); + }); + } + // + // Stop all the scripts + // + if('stop' == action) { + var serviceFiles = readdirSync(path.join(forever.config.get('root'), 'services')); + serviceFiles.forEach(function(serviceFile) { + forever.stop(fs.readFileSync(serviceFile)); + }); + } + // + // Restart all the scripts + // + if('restart' == action) { + var serviceFiles = readdirSync(path.join(forever.config.get('root'), 'services')); + serviceFiles.forEach(function(serviceFile) { + forever.restart(fs.readFileSync(serviceFile)); + }); + } +} + // // ### function columns (action, value) // #### @action {string} The subaction to execute