Auto-restart MariaDB when it dies

I am running a small, low-memory VPS where MariaDB is frequently killed by the system due to lack of memory. Since I wanted to keep the budget fixed and didn’t have enough time to look under the hood to find the root cause, I opted in for running a cron to periodically check and start MariaDB if its not running.

* * * * * /bin/systemctl status mariadb.service > /dev/null || /bin/systemctl start mariadb.service

The double pipe || means OR and will execute the 2nd command if the first command fails somehow. (Returns an exit code greater than zero.)

Leave a Reply