start unicorn app server when the ubuntu server starts

Jeevan Dongre picture Jeevan Dongre · Apr 3, 2013 · Viewed 14.4k times · Source

I am running my rails application using ruby enterprise edition with unicorn as app server. I run this command

bundle exec unicorn -D -c /home/ubuntu/apps/st/config/unicorn.rb

I need to run this command soon after the system reboots or starts. I am running the app on ubuntu 10.04 LTS EC2 instance. I tried couple of examples which are mentioned on this site as well as this site but it’s not working for me. Any heads up

Answer

warantesbr picture warantesbr · Apr 3, 2013

Try it as an Upstart. To do so, you need to create a myapp.conf file into the directory /etc/init/ with the contents below:

description "myapp server"

start on runlevel [23]
stop on shutdown
exec sudo -u myuser sh -c "cd /path/to/my/app && bundle exec unicorn -D -c /home/ubuntu/apps/st/config/unicorn.rb"

respawn

After that, you should be able to start/stop/restart your app with the commands below:

start myapp
stop myapp
restart myapp

Use ps -aux | grep myapp to check if your app is running.