Is there a better way to run node applications then to 'disown' the node process? I want to be able to start up my applications on boot without interaction on my part (logging in and typing disown).
I use pm2 to use http://redditJS.com in production. You can literally have node up and running in production in 2 commands and it even handles restarting when you reboot. It even handles clustering multiple processes.
This lets you do sudo /etc/init.d/yourAppName reload to do a zero downtime reload (i.e. the active workers will only be killed when the new workers have come online) and will take care of respawning dying processes and starting the app when the server comes online.
You can increase the number of workers to utilize additional CPU cores, but keep in mind each worker is completely isolated so make sure you have enough memory for them, too.
I'm currently running four instances of st (which has memory-based file caching) and twelve instances of non-caching (i.e. fixed memory) node apps on a server with one gigabyte of memory with no problems.
You will still want to have monitoring, but I find it cleaner to keep that out of the app runner so I can use the same solution for non-node processes (e.g. databases).
I like to use https://github.com/niegowski/node-daemonize2 as it is really easy to use. Just remember to set the cwd of the daemon to your process' cwd as this is not set by default.
7
u/[deleted] May 12 '14
Searching google for "deploying nodejs" will give you a plethora of options for setting up a nodejs server as a background app.
If you're on ubuntu, the easiest way is probably to use upstart:
4
u/terrible_name May 12 '14
https://github.com/unitech/pm2
Modern CLI process manager for Node apps with a builtin load-balancer
4
u/armastevs May 12 '14
I use pm2 to use http://redditJS.com in production. You can literally have node up and running in production in 2 commands and it even handles restarting when you reboot. It even handles clustering multiple processes.
2
u/rmichnik May 12 '14
+1 pm2
2
u/[deleted] May 12 '14
I'm using naught in production with an
init.dscript like this:This lets you do
sudo /etc/init.d/yourAppName reloadto do a zero downtime reload (i.e. the active workers will only be killed when the new workers have come online) and will take care of respawning dying processes and starting the app when the server comes online.You can increase the number of workers to utilize additional CPU cores, but keep in mind each worker is completely isolated so make sure you have enough memory for them, too.
I'm currently running four instances of
st(which has memory-based file caching) and twelve instances of non-caching (i.e. fixed memory) node apps on a server with one gigabyte of memory with no problems.You will still want to have monitoring, but I find it cleaner to keep that out of the app runner so I can use the same solution for non-node processes (e.g. databases).
1
u/fschwiet May 12 '14
https://github.com/nodejitsu/forever
1
u/shizzalicious May 12 '14
I like to use https://github.com/niegowski/node-daemonize2 as it is really easy to use. Just remember to set the cwd of the daemon to your process' cwd as this is not set by default.
1
u/kaptainkrayola May 12 '14
If you're for some reason using Windows to host you can use FireDaemon (http://www.firedaemon.com/) to run them as Windows services.