When a service such as a game server, a database or a web server crashes, it should come back up on its own if at all possible. In the past this absolutely required an extra program such as monit. Today systemd already ships with this feature. monit is still useful, however, when you want to check not only “is the process running?” but also “is it responding?”.
Option 1: systemd – no extra software
For an existing service you create an override file (drop-in). The original unit stays unchanged and is not overwritten by package updates:
sudo systemctl edit mariadb
In the editor, enter the following between the comment lines:
[Unit]
StartLimitIntervalSec=300
StartLimitBurst=5
[Service]
Restart=on-failure
RestartSec=10s
Restart=on-failure– restart when the service exits with an error or crashes (not after an intentionalsystemctl stop). Alternativelyalways.RestartSec=10s– wait ten seconds before restarting.StartLimitBurst/StartLimitIntervalSec– at most five restarts within five minutes. After that systemd gives up instead of restarting the service endlessly.
Check and test:
systemctl show mariadb -p Restart -p RestartUSec
sudo kill -9 $(systemctl show -p MainPID --value mariadb) # simulate a crash
systemctl status mariadb # is it running again?
journalctl -u mariadb -n 20
Option 2: monit – also checks whether the service responds
A process can be running and still be hung. monit additionally checks ports, HTTP responses, memory and CPU usage and can send an e-mail when there are problems.
# Ubuntu / Debian
sudo apt install monit
# Fedora (EPEL on RHEL)
sudo dnf install monit
Your own checks go into /etc/monit/conf.d/ on Debian/Ubuntu and into /etc/monit.d/ on Fedora. Example for nginx, /etc/monit/conf.d/nginx:
check process nginx with pidfile /run/nginx.pid
start program = "/usr/bin/systemctl start nginx"
stop program = "/usr/bin/systemctl stop nginx"
if failed host 127.0.0.1 port 80 protocol http then restart
if totalmem > 500 MB for 5 cycles then restart
if 3 restarts within 5 cycles then unmonitor
For programs without a PID file there is check process name matching "program-name". A UDP port, for a game server for instance, is checked with if failed port 9987 type udp then restart.
Test the configuration and apply it:
sudo monit -t
sudo systemctl enable --now monit
sudo monit reload
sudo monit status
For e-mail notifications, enter a mail server and a recipient in the main configuration (/etc/monit/monitrc):
set mailserver smtp.example.org port 587
username "server@example.org" password "secret"
using tls
set alert admin@example.org
Which option?
For most services systemd is entirely sufficient and needs no additional software. monit is worthwhile when services hang instead of crashing, when resources are to be monitored or when you want to be informed by e-mail about problems. The two can also be combined: monit should then start and stop the services through systemctl, as in the example above.
Originally published in 2009 (monit on Fedora for a TeamSpeak server), completely revised in November 2026.