Automatically restart services if down?

There is no need for monit or other additional programs to restart failed services, systemd has this functionality built-in see manual

Also mysql service is configured to restart itsef “on-abort” ( cat /etc/systemd/system/mysqld.service ) so any workarounds you had to configure previously are probably not needed anymore

# Restart crashed server only, on-failure would also restart, for example, when
# my.cnf contains unknown option
Restart=on-abort
RestartSec=5s

But If you still want to change the restart condition to “on-failure” or “always” , extend the unit file :

mkdir -p /etc/systemd/system/mariadb.service.d
echo -e "[Service]\nRestart=on-failure" > /etc/systemd/system/mariadb.service.d/my.conf
systemctl daemon-reload
2 Likes