Linux: upstart job

Made a newbie mistake on my aws server.  Started a node.js server as a user (node server.js &) and didn’t realize that after I logged out the node.js server would go down with it.  Once I set the node.js to an upstart job it now start automatically and persistantly.

You have to create an upstart job. That way your app will start once linux loads, and you can start / stop / restart it by sudo start yourappsudo restart yourapp etc.

Here are the steps:

1) Install upstart utility

sudo apt-get install upstart

2) Create upstart script for your node app:

in /etc/init add file yourappname.conf with the following lines of code:

description "your app name"

start on started mountall
stop on shutdown

# Automatically Respawn:
respawn limit 99 5

env NODE_ENV=development

exec node /path_to_your_app/app.js >> /var/log/yourappname.log 2>&1

3) start your app by sudo start yourappname

sudo stop yourappname

sudo restart yourappname


This entry was posted in Linux and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s