Make Upstart script work in Linux (Ubuntu)
For my Node.js app, I wanted to have upstart script which will hold server up even after EC2 instance is gone for reboot. While looking everywhere, I used to have such script:
description "myapp server" start on started mountall stop on shutdown respawn script cd /var/www/myapp exec node server/main.js --logFile=logs/server.log 1>logs/server-error.log 2>logs/server-error.log end script
First of all, started mountall and shutdown didn’t work for me. So, I looked at other scripts under /etc/init and they had runlevel defined as start/stop commands.
Second, if you’re using deployment tool (e.g. Capistrano) as I am, those log files won’t have same permissions as me (in my case they belong to deploy user). In that case you should use different location for logging. I chose /var/log. So, my final script working on local machine and EC2 server is:
description "myapp server" start on runlevel  stop on runlevel [!2345] respawn script cd /var/www/myapp/current exec node server/main.js --logFile=/var/log/myapp-server.log 1>/var/log/myapp-error.log 2>/var/log/myapp-error2.log end script
Let me know if you have any issues.
Share this story:
Leave a Reply