Skip to content

Commit

Permalink
[fix] services should be added to run levels during install
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeck authored and indexzero committed Oct 9, 2011
1 parent f2026b3 commit 782cca7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 4 additions & 4 deletions init.d/forever-services
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Source function library.
. /lib/lsb/init-functions
path=$path:/user/local/bin
PATH=$PATH:/usr/local/bin

NAME=forever-services
pidfile=/var/run/$NAME.pid
Expand All @@ -24,7 +24,7 @@ awk=awk
sed=sed

start() {
echo "Starting $NAME node instance: "
echo "Starting $NAME: "

if [ "$id" = "" ]; then
# Create the log and pid files, making sure that the target use has access to them
Expand All @@ -43,7 +43,7 @@ start() {
}

restart() {
echo -n "Restarting $NAME node instance : "
echo -n "Restarting $NAME: "
if [ "$id" != "" ]; then
$forever service-restart -p $forever_dir
RETVAL=$?
Expand All @@ -53,7 +53,7 @@ restart() {
}

stop() {
echo -n "Shutting down $NAME node instance : "
echo -n "Shutting down $NAME: "
if [ "$id" != "" ]; then
$forever service-stop -p $forever_dir
else
Expand Down
16 changes: 15 additions & 1 deletion lib/forever/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ cli['service-install'] = function () {
//
forever.config.set('root', path.join('/var', 'local', 'forever'));
forever.log.info('Creating service environment.');
var initdPath = path.join('/etc', 'init.d', 'forever-services');
try {
fs.mkdirSync(forever.config.get('root'), 0777);
fs.mkdirSync(path.join(forever.config.get('root'), 'services'), 0777);
Expand All @@ -272,11 +273,22 @@ cli['service-install'] = function () {
}
forever.log.info('Installing init.d script.');
var script = fs.createReadStream(path.join(__dirname, '..', '..', 'init.d', 'forever-services'));
var target = fs.createWriteStream(path.join('/etc', 'init.d', 'forever-services'), {
var target = fs.createWriteStream(initdPath, {
flags: 'w',
mode: 0777
});
script.pipe(target);
script.on('end', function() {
forever.log.info('Adding init.d script to run levels');
var directories = fs.readdirSync('/etc');
directories.forEach(function (directory) {
var match = directory.match(/^rc(\d+)\.d$/);
if(match) {
var kill_or_start = {0:true, 1:true, 6:true}[match[1]] ? 'K' : 'S';
fs.symlinkSync(initdPath, path.join('/etc',directory,kill_or_start+'20forever-services'));
}
});
});
}
cli['service-start'] = function (file, options) {
//
Expand All @@ -289,6 +301,7 @@ cli['service-start'] = function (file, options) {
return;
}
var monitors = [];
process.title = 'forever-services';
serviceFiles.forEach(function (serviceFile, index) {
var serviceFilePath = path.join(forever.config.get('root'), 'services', serviceFile);
var service = JSON.parse(fs.readFileSync(serviceFilePath));
Expand Down Expand Up @@ -331,6 +344,7 @@ cli['service-restart'] = function (file, options) {
forever.log.info('No services found.');
return;
}

serviceFiles.forEach(function (serviceFile) {
var serviceFilePath = path.join(forever.config.get('root'), 'services', serviceFile);
var service = JSON.parse(fs.readFileSync(serviceFilePath));
Expand Down

0 comments on commit 782cca7

Please sign in to comment.