Skip to content

Commit

Permalink
[api] Revive the service api stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeck authored and indexzero committed Oct 9, 2011
1 parent 620a362 commit 93053d6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/forever
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var action, accepts = [
'clear',
'columns',
'list',
'service',
'start',
'stop',
'stopall',
Expand Down
59 changes: 59 additions & 0 deletions lib/forever/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93053d6

Please sign in to comment.