Question

Nginx and Unicorn Boot Question - Run On Start up?

  • Posted June 16, 2014

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

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

On CentOS, to ensure that nginx starts on reboot run: <pre> sudo chkconfig --levels 235 nginx on </pre> Then for Unicorn to start on boot, you’d need to write an init script and save it to <code>/etc/init.d/unicorn</code> 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: <pre> service unicorn stop service unicorn start </pre> And to make it run on boot, set: <pre> sudo chkconfig --levels 235 unicorn on </pre>