Search code examples
ruby-on-railsrubyruby-on-rails-3unicorn

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


Solution

  • 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.