Make your weak ass node process strong like bull

Ok so your shit keeps shutting off. Every time you restart your server or echo anything to the terminal through STDOUT – your node process goes all to shit and you have to log on and get it running again…something like:

node server.js&

Well, screw that. We’re not going to take this shit any longer. On your ubuntu installation there’s something called upstart (unless you have some sort of weird ass installation). We are going to make your node process run, even if your entire server suddenly bursts into flames and the sys admin decides water is the best solution…

Change directories to:

cd /etc/init

Then make a new file:

sudo pico accelerometer.conf

It just has to be “.conf”. Ok now paste the following in and change the path to your node file:

description "node.js server"
author      "kvz - http://kevin.vanzonneveld.net"

# used to be: start on startup
# until we found some mounts weren't ready yet while booting:
start on started mountall
stop on shutdown

# Automatically Respawn:
respawn
respawn limit 99 5

script
    # Not sure why $HOME is needed, but we found that it is:
    export HOME="/root"

    exec /usr/bin/node /home/ubuntu/www/accelerometer/accelerometer.js >> /var/log/node.log 2>&1
end script

post-start script
   # Optionally put a script here that will notifiy you node has (re)started
   # /root/bin/hoptoad.sh "node.js has started!"
end script

I didn’t write the previous, this guy did but he seems really smart, so don’t f*** with it.

now run the shit:

sudo start accelerometer

That’s it. Should be up and running like a hamster in one of those wheels that we think are so fun, but are actually a hamster’s version of the ho chi minh.

Leave a Reply

Your email address will not be published. Required fields are marked *