You Are Here: Home » Uncategorized

Restart Service Automatically Once it Fails

By Debjit on November 1st, 2021 
Advertisement

There are two ways to do this - source.

  1. Use monit which purpose is to take care of situations like this.
apt install monit

nano /etc/monit/conf.d/nginx.conf

Put content below inside this file and restart monit

check process nginx with pidfile /var/run/nginx.pid
start program = "/usr/sbin/service nginx start"
stop program = "/usr/sbin/service nginx stop"

2. It is a feature of SystemD. Override existing unit file for NGINX by running systemctl edit nginx then paste in:

[Service]
Restart=always

Save.

If NGINX is down due to, e.g. the OOM killer, it will be restarted after dying. If you have a configuration error in NGINX, it will not be restarted, of course.

To verify this configuration. start NGINX service with systemctl start nginx, and verify it is running with systemctl status nginx.

Kill it via pkill -f nginx. Confirm that NGINX is running anyway with systemctl status nginx.

Restart Nginx Automatically Once it Fails

Restart Apache Automatically Once it Fails

Restart Mysql Automatically Once it Fails

Restart Postgresql Automatically Once it Fails

Restart Nginx Automatically Once it Fails

Advertisement







Restart Service Automatically Once it Fails was originally published on Digitizor.com on November 1, 2021 - 5:06 pm (Indian Standard Time)