Launch Nginx on startup

Prabu D

1 min read

I would like to run nginx process automatically when server reboot. Unfortunately Last week Rackspace folks rebooted servers due to their maintanance. But we should show 0% down time for our customers. i.e, whenever the server rebooted the nginx should come up automatically.
To start the nginx process manually just type the below command.
[source]
sudo /opt/nginx/sbin/nginx
[/source]
I heard that the following command will set the service at startup.
[source]
To configure nginx to start at system boot:
on RedHat like systems:
sudo /sbin/chkconfig –level 345 /etc/init.d/nginx on
on Debian-like systems (Ubuntu):
sudo /usr/sbin/update-rc.d -f /etc/init.d/nginx defaults
on Gentoo:
sudo rc-update add /etc/init.d/nginx default
[/source]
To achieve the above automate service.
We need to create a init shell script file. One of the disadvantages of installing Nginx from source tar.gz is the fact that it does not include any init script but we can solve. follow the steps given below :
1. Let’s create the Nginx init script, I am using Ubuntu Machine.
[source]sudo nano /etc/init.d/nginx[/source]
Copy and paste the content from https://gist.github.com/continuityapp/938648 .If that script doesn’t work, you may try this one, listed at Nginx.org website.
2. Set the executable permissions.
[source]sudo chmod +x /etc/init.d/nginx[/source]
3. Add the script to the default runlevels:
[source]sudo /usr/sbin/update-rc.d -f nginx defaults[/source]
4. Now test it by running the following command.
[source]
sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx restart
[/source]
To confirm the successful setup refer the below screen shot.
nginx-startup

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *