Skip to content

Instantly share code, notes, and snippets.

@FGRibreau

FGRibreau/myapp.js

Created Mar 6, 2012
Embed
What would you like to do?
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