Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

start unicorn app server when the ubuntu server starts

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

like image 712
Jeevan Dongre Avatar asked Apr 03 '13 04:04

Jeevan Dongre


3 Answers

In my case, I just wanted it quick so I place the startup command in /etc/rc.local like below. Note that i'm using RVM.

# By default this script does nothing.
cd <your project dir>
/usr/local/rvm/gems/ruby-2.2.1/wrappers/bundle exec unicorn -c <your project dir>/config/unicorn.conf -D
test -e /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
exit 0

Make sure your startup command is above the exit 0. After you reboot, check whether it is running or not by directly hitting the url of your application or use ps -aux | grep unicorn command.

Note* Previously I use Phusion Passenger but I'm having trouble to see its error log, so I move back to unicorn. I also tried @warantesbr without success, which I guess it fails because my whole environment where setup using root access.

like image 183
Yakob Ubaidi Avatar answered Oct 14 '22 09:10

Yakob Ubaidi


You can use this file as a template, set appropriate paths mentioned in this file, make it executable and symlink into /etc/init.d/my_unicorn_server. Now you can start the server using:

sudo service my_unicorn_server start

Then you can do:

sudo update-rc.d my_unicorn_server defaults

To startup the unicorn server on system reboot automatically.

like image 20
benchwarmer Avatar answered Oct 14 '22 09:10

benchwarmer


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.

like image 16
warantesbr Avatar answered Oct 14 '22 08:10

warantesbr