Created February 16, 2012 18:41
Save FGRibreau/1846952 to your computer and use it in GitHub Desktop.
Simple snippet for cross-platform .pid management in NodeJS. I use it for managing NodeJS apps with supervisord and monit
This file contains hidden or 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 // // Usage: require('./pid')("myapp"); // var fs = require('fs'); module.exports = function(appname){ process.title = appname; var PID_FILE = "/usr/local/var/run/"+process.title+".pid"; 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); }); }; This file contains hidden or 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" PID_FILE = "/usr/local/var/run/#{process.title}.pid" fs = require("fs") fs.writeFileSync PID_FILE, "#{process.pid}\n" process.on "uncaughtException", (err) -> console.error "[uncaughtException]", err process.exit 1 process.on "SIGTERM", -> console.log "SIGTERM (killed by supervisord or another process management tool)" process.exit 0 process.on "SIGINT", -> console.log "SIGINT" process.exit 0 process.on "exit", -> console.log('Exiting...') fs.unlink PID_FILE # # Your code start here # setInterval (->), 1000 This file contains hidden or 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(function(){}, 1000);You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4