Created
March 6, 2012 12:37
-
-
Save FGRibreau/1986049 to your computer and use it in GitHub Desktop.
NodeJS Process Management at Brin.gr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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