It’s really very tough job for every System Administrator to monitor and debug Linux System Performance problems every day. After being a Linux Administrator in IT industry, I came to know that how hard is to monitor and keep systems up and running. MySql is the main service one of them. For this reason, I have created some service monitoring bash scripts. This bash script is available under all flavors of Linux and can be useful to monitor MySql service.
Create a file mysql-check.sh and put below content in that:
#!/bin/bash
mysql_daemon=’mysqld’
pgrep=’/usr/bin/pgrep’
$pgrep $mysql_daemon > /dev/null
if [ $? -ne 0 ]; then
service mysql start
fi
I am going to setup this script in cronjob for to run at every minute. So it will check MySql service at every minute and start the service if found it down.
NOTE: Please add this script in cronjob as root user.
To setup cronjob hit below command
crontab –e
and put below content at the end of file
* * * * * path_to_mysql-check.sh
ALL! Done