Skip to content

Commit

Permalink
[minor] More work for multiple processes from a single programmatic u…
Browse files Browse the repository at this point in the history
…sage
  • Loading branch information
indexzero committed Apr 20, 2011
1 parent 6e52e03 commit 6741c3a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 40 deletions.
70 changes: 35 additions & 35 deletions bin/forever
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,40 @@ require.paths.unshift(path.join(__dirname, '..', 'lib'));
var forever = require('forever');

var help = [
"usage: forever [start | stop | restart | stopall | list | cleanlogs] [options] SCRIPT [script options]",
"",
"options:",
" start start SCRIPT as a daemon",
" stop stop the daemon SCRIPT",
" stopall stop all running forever scripts",
" restart restart the daemon SCRIPT",
" list list all running forever scripts",
" cleanlogs [CAREFUL] Deletes all historical forever log files",
"",
" -m MAX Only run the specified script MAX times",
" -l LOGFILE Logs the forever output to LOGFILE",
" -a, --append Append logs",
" -o OUTFILE Logs stdout from child script to OUTFILE",
" -e ERRFILE Logs stderr from child script to ERRFILE",
" -d SOURCEDIR The source directory for which SCRIPT is relative to",
" -p PATH Base path for all forever related files (pid files, etc.)",
" -c COMMAND COMMAND to execute (defaults to node)",
" --pidfile The pid file",
" -v, --verbose Turns on the verbose messages from Forever",
" -s, --silent Run the child script silencing stdout and stderr",
" -h, --help You're staring at it",
"",
"[Long Running Process]",
" The forever process will continue to run outputting log messages to the console.",
" ex. forever -o out.log -e err.log my-script.js",
"",
"[Daemon]",
" The forever process will run as a daemon which will make the target process start",
" in the background. This is extremely useful for remote starting simple node.js scripts",
" without using nohup. It is recommended to run start with -o -l, & -e.",
" ex. forever start -l forever.log -o out.log -e err.log my-daemon.js",
" forever stop my-daemon.js",
""
'usage: forever [start | stop | restart | stopall | list | cleanlogs] [options] SCRIPT [script options]',
'',
'options:',
' start start SCRIPT as a daemon',
' stop stop the daemon SCRIPT',
' stopall stop all running forever scripts',
' restart restart the daemon SCRIPT',
' list list all running forever scripts',
' cleanlogs [CAREFUL] Deletes all historical forever log files',
'',
' -m MAX Only run the specified script MAX times',
' -l LOGFILE Logs the forever output to LOGFILE',
' -a, --append Append logs',
' -o OUTFILE Logs stdout from child script to OUTFILE',
' -e ERRFILE Logs stderr from child script to ERRFILE',
' -d SOURCEDIR The source directory for which SCRIPT is relative to',
' -p PATH Base path for all forever related files (pid files, etc.)',
' -c COMMAND COMMAND to execute (defaults to node)',
' --pidfile The pid file',
' -v, --verbose Turns on the verbose messages from Forever',
' -s, --silent Run the child script silencing stdout and stderr',
' -h, --help You\'re staring at it',
'',
'[Long Running Process]',
' The forever process will continue to run outputting log messages to the console.',
' ex. forever -o out.log -e err.log my-script.js',
'',
'[Daemon]',
' The forever process will run as a daemon which will make the target process start',
' in the background. This is extremely useful for remote starting simple node.js scripts',
' without using nohup. It is recommended to run start with -o -l, & -e.',
' ex. forever start -l forever.log -o out.log -e err.log my-daemon.js',
' forever stop my-daemon.js',
''
].join('\n');

var mappings = {
Expand Down Expand Up @@ -136,7 +136,7 @@ function tryStart (callback) {
options.pidFile = options.pidFile || uid + '.pid';
options.logFile = argv.l || uid + '.log';

fullLog = forever.logFilePath(options.logFile);
fullLog = forever.logFilePath(options.logFile, uid);
fullScript = path.join(options.sourceDir, file);

forever.stat(fullLog, fullScript, options.appendLog, function (err) {
Expand Down
2 changes: 1 addition & 1 deletion examples/chroot.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ daemon.chroot('/tmp/chroot');
sys.puts('Working in chroot');

setInterval(function () {
fs.readdir("./", function (err, files) {
fs.readdir('./', function (err, files) {
sys.puts('Current directory: ' + process.cwd());
sys.puts('err: ' + sys.inspect(err));
sys.puts('files: ' + sys.inspect(files));
Expand Down
14 changes: 14 additions & 0 deletions examples/multiple-processes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require.paths.unshift(require('path').join(__dirname, '..', 'lib'));

var util = require('util'),
forever = require('forever'),
path = require('path'),
script = path.join(__dirname, 'server.js');

var child1 = new (forever.Forever)(script, { 'options': [ "--port=8080"] });
child1.start();
util.puts('Forever process running server.js on 8080');

var child2 = new (forever.Forever)(script, { 'options': [ "--port=8081"] });
child2.start();
util.puts('Forever process running server.js on 8081');
8 changes: 4 additions & 4 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,11 @@ forever.randomString = function (bits) {
// #### @logFile {string} Log file path
// Determines the full logfile path name
//
forever.logFilePath = function(logFile) {
if (logFile && logFile[0] === "/") {
forever.logFilePath = function(logFile, uid) {
if (logFile && logFile[0] === '/') {
return logFile;
} else {
return path.join(forever.config.get('root'), logFile || "forever.log");
return path.join(forever.config.get('root'), logFile || (uid || 'forever') + '.log');
}
};

Expand All @@ -437,7 +437,7 @@ forever.logFilePath = function(logFile) {
// Determines the full pid file path name
//
forever.pidFilePath = function(pidFile) {
if (pidFile && pidFile[0] === "/") {
if (pidFile && pidFile[0] === '/') {
return pidFile;
} else {
return path.join(forever.config.get('pidPath'), pidFile);
Expand Down

0 comments on commit 6741c3a

Please sign in to comment.