foreverize

A tool for allowing a process to automatically foreverizing itself

Foreverize: in Soviet Russia, your server keeps itself up

Foreverize is a handy tool that makes it really easy to your server code to incorporate forever-monitor automatically.

This version is going up on github/npm by popular demand, but is in no way ready for the general public yet...

TODO list:

  1. remove config/forever.json dependency (possibly put config into package.json)
  2. remove hard-coded log paths
  3. allow full config options that forever.Monitor supports
  4. remove all the logging to stdout
  5. cleanup code

Wish list:

  1. zero-downtime restarts
$ npm install foreverize

Install required dependencies (or through package.json)

$ npm install forever
$ npm install foreverize

In your server.js

var start_server = function(){
  require("http").createServer().listen(1337);
}
 
var foreverize = require("foreverize");
foreverize();
if(!foreverize.isMaster){
  start_server();
}

Now if your HTTP server crashes, it'll respawn itself. You can also use the normal forever commands to manage the process.

$ node_modules/.bin/forever list
info:    Forever processes running
data:        uid                command                        script                                          forever pid   logfile                                               uptime     
data:    [0] foreverize_example /usr/local/nvm/v0.8.8/bin/node /home/ilya/work/cm/foreverize_example/server.js 26326   26329 /home/ilya/work/cm/foreverize_example/log/forever.log 0:0:0:5.61    

I welcome pull requests!

This software is distributed under the MIT License.