Linux How to automatically restart failed service after crash using monit configuration

Опубликовано: 21 Март 2026
на канале: ITSolutions
7,232
35

http://bit.ly/it-solutions-subscribe ### Subscribe ###
Instructions

I had problem with crashing web service emby server. I successfully solved problem using MONIT program.
It allows to check port ... and restart process/service.

I am using "emby-server" change it to name of your service

1. systemctl status emby-server - to chceck status of service
2. sudo kill xxxxx - to kill procces, you need to find PID number yourself
3. sudo apt-get install monit (Debian / Ubuntu)
sudo yum install monit (Centos / RedHat)
4. sudo systemctl restart emby-service - start service
You can check list of running services PIDs by typing:
ls /var/run/
5. cat /var/run/emby-service.pid - heres PID of my service regardless randomizing casued by restaring
you can compare it with command systemctl status emby-server
6. sudo nano /etc/monit/monitrc - configure monit (go to bottom)

before include /etc/monit/conf.d/* add:
check process emby-server with pidfile /var/run/emby-server.pid

start program = "/etc/init.d/emby-server start"
stop program = "/etc/init.d/emby-server stop"

if failed host localhost port 8096 then restart (use port of your webservice)

after include /etc/monit/conf.d/*

set httpd port 2812 and
use address localhost
allow localhost
(this will allow you to open webservice own webinterface)
Save file (CTRL + O ) and exit (CTRL + X)
7.sudo systemctl restart monit - restart monit
8.ps -aux | grep emby - service is dead but we will check if the process emby is running
Now monit will restarting process emby-server but not the service
9. sudo nano /etc/monit/monitrc - lets change monit configuration file (go to bottom)
10. use # to comment previous start program / stop program
11. start program = "/bin/systemctl start emby-server"
stop program = "/bin/systemctl/stop emby-server"
dont use just start program = "systemctl start emby server" because service won't be restarted and you will have to search for monit error logs
Save file (CTRL + O ) and exit (CTRL + X)
12. sudo systemctl restart monit - restart monit again
13. sudo nano /etc/monit/monitrc
set daemon 120
change to desired value (seconds)
save (CTRL + O) and exit (CTRL + X)
14. sudo systemctl restart monit (restart monit one more time).

Monit Documentation
http://viid.me/qaAlS3

Configuration Examples (Cron, Raid, SSHD, Apache, Ngix, MySql, PostgreSQL, Samba and others)
http://viid.me/qaPZ8G

Examples (Apache, Ngix, Mariadb, PHP-FPM, SSH, Cron, Postfix, MongoDB)
http://viid.me/qaAxWu

How to install and configure monit
http://viid.me/qaAzDf