Restart Service Automatically Once it Fails
There are two ways to do this - source.
- 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