Skip to content

Instantly share code, notes, and snippets.

@FGRibreau
Created March 6, 2012 12:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FGRibreau/1986049 to your computer and use it in GitHub Desktop.
Save FGRibreau/1986049 to your computer and use it in GitHub Desktop.
NodeJS Process Management at Brin.gr
//
// The following snippet must be inserted at the top of your main js file
//
process.title = "myapp";
var PID_FILE = "/usr/local/var/run/"+process.title+".pid"
, fs = require('fs');
fs.writeFileSync(PID_FILE, process.pid+"\n");
process.on("uncaughtException", function(err) {
console.error("[uncaughtException]", err);
return process.exit(1);
});
process.on("SIGTERM", function() {
console.log("SIGTERM (killed by supervisord or another process management tool)");
return process.exit(0);
});
process.on("SIGINT", function() {
console.log("SIGINT");
return process.exit(0);
});
process.on("exit", function() {
return fs.unlink(PID_FILE);
});
//
// Your code start here
//
setInterval(console.log.bind(console, "i'm aliiive"), 1000);
with pidfile /usr/local/var/run/myapp.pid
start program = "/usr/bin/supervisorctl start myapp"
stop program = "/usr/bin/supervisorctl stop myapp"
if 10 restarts within 10 cycles
then timeout
[program:myapp]
command=node myapp.js ; the program (relative uses PATH, can take args)
directory=/www/app/ ; directory to cwd to before exec (def no cwd)
process_name=myapp ; process_name expr (default %(program_name)s)
autorestart=true ; whether/when to restart (default: unexpected)
startsecs=1 ; number of secs prog must stay running (def. 1)
stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
stdout_logfile=/var/log/myapp.log ; stdout log path, NONE for none default AUTO
stderr_logfile=/var/log/myapp.err.log ; stderr log path, NONE for none default AUTO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment