解救mysql 及 apache 無預期掛掉後自行復活

#!/bin/bash
PATH=/usr/sbin:/usr/bin:/sbin:/bin
if  [ ! "$(/usr/sbin/service mysql status)" =~ "start/running" ]
then
    echo "MySQL restarted" | mail -s "Email Subject" email@domain.com
    sudo service mysql start
fi

https://cssjockey.com/how-to-create-a-cron-job-to-start-mysql-if-it-stops/

#!/bin/sh

ps auxw | grep apache2 | grep -v grep > /dev/null

if [ $? != 0 ]
then
        /etc/init.d/apache2 start > /dev/null
fi

https://www.digitalocean.com/community/tutorials/how-to-use-a-simple-bash-script-to-restart-server-programs

寫文script後再用cron job每隔一段時間去跑

留言

熱門文章