diff --git a/init.d/forever-services b/init.d/forever-services index 7d085ce3..3d4b8025 100644 --- a/init.d/forever-services +++ b/init.d/forever-services @@ -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 @@ -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 @@ -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=$? @@ -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 diff --git a/lib/forever/cli.js b/lib/forever/cli.js index 9fa5832b..04e2bce2 100644 --- a/lib/forever/cli.js +++ b/lib/forever/cli.js @@ -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); @@ -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) { // @@ -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)); @@ -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));