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

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
LVL 1
YashyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
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.
YashyAuthor 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 EngineerCommented:
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).
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

Prabhin MPDevOps EngineerCommented:
use the below command to make nginx service starts while booting

chkconfig nginx on

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
YashyAuthor 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?
YashyAuthor 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 EngineerCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.