Automatically check MariaDB to ensure it is running

I’ve noticed on a couple occasions (on different servers) that MariaDB will “die”. On the first server, this was related to the server running out of memory. I’m not sure about the other server I noticed this on yet. In any case, I simply wrote a small bash script to check the status of MariaDB every ten minutes, and restart it if it’s down. Here’s what the script looks like…


echo "Checking whether MariaDB is running or not."
if [ $(/bin/systemctl status mariadb.service | grep -c "active (running)") -gt 0 ]; then
 echo "MariaDB is running. "
 echo "MariaDB is not running. Starting MariaDB service."
 /bin/systemctl restart mariadb.service

Then I just call the script every ten minutes in a cronjob like this…

*/10 * * * * /root/cronscripts/ > /dev/null


Leave a Comment