Question

Nginx and Unicorn Boot Question - Run On Start up?

Posted June 16, 2014 6.7k views
I finally got my rails server up and running on CentOS with Nginx and unicorn. But I noticed the each time the server reboots or power cycles, I have to run "service nginx start" manually and then go into each site and run "unicorn_rails -c config/unicorn.rb -D" for the site(s) to come up. Is there a way to automate this process when the server boots up? Thank you

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer
On CentOS, to ensure that nginx starts on reboot run:
sudo chkconfig --levels 235 nginx on
Then for Unicorn to start on boot, you'd need to write an init script and save it to /etc/init.d/unicorn Here's an example one: https://gist.github.com/mustafaturan/2762372 Make sure to change the variables at the top of the file to match your project. You'll then be able to start and stop your app with:
service unicorn stop
service unicorn start
And to make it run on boot, set:
sudo chkconfig --levels 235 unicorn on
  • If you get the error service unicorn does not support chkconfig from using the above script, you need to add the following to the top of the script (after the first line):

    # chkconfig: 2345 95 20
    # description: Controls Unicorn rails server
    # processname: unicorn
    
  • If you use Ubuntu, before using service execute these commands:

    sudo update-rc.d <script_name> defaults
    sudo update-rc.d <script_name> enable
    
Submit an Answer