How do you ensure Nginx services start automatically after restarting linux server?

Yashy
Yashy used Ask the Experts™
on
Hi guys

We have an Linux instance in the cloud with Nginx installed on it. However, whenever the server restarts, the Nginx services don't. I'm not overly familiar with Linux commands. Can anyone help me how we can automate the Nginx services to start on restarts automatically?

Thanks for helping
Yash
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Commented:
1) You should use a standard Distro, like Ubuntu.

2) You should install NGINX via the package repository.

3) If you do #1 + #2, then the packaging system will setup correct OpenRC or systemd start/stop plumbing.

4) If you install some other way besides #1 + #2, you will have to roll your own start/stop plumbing.

Best starting point is to describe your Distro + how you installed NGINX.

Author

Commented:
Hi David,

Thank you for responding. The Linux server I am referring to is an Amazon EC2 instance. I believe the package would have been installed by using the 'yum' command. But I didn't do it myself. Someone else would have.

Any way of finding out?

Thanks
Yash
nociSoftware Engineer
Distinguished Expert 2018
Commented:
This is probably a redhat, CentOS like server...
V5: and older: chkconfig --add nginx   # if already added: chkconfig nginx on
V6 i am not sure: if systemd is used: See V7, if sysV startup is used V5
V7 uses systemd: systemctl add nginx

Anyway one of the above methods should help.
During logon you can probably see which system is used...
(/etc/issue   might tell it as well, YYMV there though).
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

DevOps Engineer
Distinguished Expert 2018
Commented:
use the below command to make nginx service starts while booting

chkconfig nginx on

Author

Commented:
So I've typed sudo chkconfig nginx on. Now I've typed 'sudo chkconfig --list' and it shows the below:


 0:off   1:off   2:on    3:on    4:on    5:on    6:off

How do I know what each of these columns mean and whether it means service is on after startup?

Author

Commented:
I think I've worked it out now. Number 3 is what I'm looking for Multi-user mode with networking starts up normally, which i assume means it auto starts after a reboot.
nociSoftware Engineer
Distinguished Expert 2018
Commented:
0: = shutdown
1: = single user mode
2: = minimal boot
3: = normal
4: = minimal including graphics
5: = Normal including graphics
6: = restart (reboot).

So your service starts in all regular modes
It does not start in shutdown (duh..) single user mode (when almost nothing runs, disks are not mounted etc.),  or when the system is rebooting.


Your system still uses SYSV startup.
and 3 (non graphic console) or 5 (graphic console) are regular modes to run with.
3 is mostly for servers, routers etc., 5 is for desktops, workstations etc.

you can find the default with:   grep :initdefault: /etc/inittab

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial