Tag Archive for 'MariaDB'

Automated Database Restart

Here is a script that checks to ensure the database is running and restarts the service if it is not running.  This was used on a very low memory server to ensure a database remained operational, despite it sometimes crashing due to out of memory errors.

#!/bin/bash

timestamp="$(date)"
systemctl stop httpd && echo "${timestamp}" Stopping Apache... >> /home/centos/administration/apache.log
systemctl is-active mariadb && echo "${timestamp}" MariaDB is active so not starting >> /home/centos/administration/mariadb_active.log || echo "${timestamp}" MariaDB is not Active >> /home/centos/administration/mariadb_inactive.log
systemctl is-active mariadb && echo "${timestamp}" No need to restart MariaDB || systemctl start mariadb
systemctl start httpd && echo "${timestamp}" restarting apache...>> /home/centos/administration/apache.log