Serviso tikrinimas ir perkrovimas

Iš Žinynas.
Jump to navigation Jump to search

Skriptas skirtas nurodyto serviso tikrinimui bei paleidimui, jeigu jis neveikia. Taip pat jeigu servisas is naujo neprisikelia, pranesti el.pastu.

#!/bin/bash
PROC="mysqld"
COMD="/etc/init.d/mysqld start"
MAIL="justinas@eofnet.lt"
echo -n "Checking if mysql service is running.. "
if [[ -z $(ps -ef |grep -v grep |grep $PROC) ]]
then
   echo "[Dead]"
   echo "Restarting..."
   $COMD
   [ $?  -eq "0" ] && echo "Process $COMD restart complete!" || echo "`hostname` - process - $PROC - unable to sart" | mail -n -s "Server status: `hostname`" $MAIL
else
   echo "[Running]"
fi