#!/bin/bash # Add any services to be watched by the watchdog to the SERVICE_LIST # Format of the service list: "Display Name" "Service Name" "semicolon delimited list of watchdog arguments" SERVICE_LIST=( "LiteSpeed" "lsws" "lsws;web;litespeed;openlitespeed" "MariaDB" "mariadb" "mariadb;database;mysql" "PowerDNS" "pdns" "powerdns;dns" "Dovecot" "dovecot" "dovecot;imap;pop3" "PostFix" "postfix" "postfix;smtp" "Pure-FTPd" "pure-ftpd" "pureftpd;pure-ftpd;ftp" ) SERVICE_COUNT=$((${#SERVICE_LIST[@]}/3)) show_help() { echo -e "\nrun command: \e[31mnohup bash /etc/cyberpanel/watchdog.sh SERVICE_NAME >/dev/null 2>&1 &\e[39m" echo -e "\nreplace \e[31mSERVICE_NAME\e[39m to the service name, acceptable word:" for ((x=0; x /dev/null 2>&1 & echo -e "\nWatchDog for ${DISPLAY_NAME} has been started..." else echo -e "\nWatchDog for ${DISPLAY_NAME} is running...\n" echo $(ps aux | grep "watchdog ${SERVICE_ARG}" | grep -v grep) fi done } check_service() { systemctl status $NAME 2>&1>/dev/null if [[ $? == "0" ]] ; then if [[ $NAME == "mariadb" ]] ; then pid=$(ps aux | grep "/usr/sbin/mysqld" | grep -v grep | awk '{print $2}') if [[ $pid != "" ]] ; then echo "-1000" > /proc/$pid/oom_score_adj fi pid=$(ps aux | grep "/usr/sbin/mysqld" | grep -v grep | awk '{print $2}') if [[ $pid != "" ]] ; then echo "-1000" > /proc/$pid/oom_score_adj fi fi echo "$NAME service is running..." else echo "$NAME is down , try to restart it..." if [[ $NAME == "lsws" ]] ; then pkill lsphp fi if [[ $NAME == "mariadb" ]] ; then pid=$(ps aux | grep "/usr/sbin/mysqld" | grep -v grep | awk '{print $2}') if [[ $pid != "" ]] ; then echo "-1000" > /proc/$pid/oom_score_adj fi pid=$(ps aux | grep "/usr/sbin/mysqld" | grep -v grep | awk '{print $2}') if [[ $pid != "" ]] ; then echo "-1000" > /proc/$pid/oom_score_adj fi fi systemctl stop $NAME systemctl start $NAME if [ -f /etc/cyberpanel/watchdog.flag ] ; then flag="/etc/cyberpanel/watchdog.flag" LINE3=$(awk 'NR==3' $flag) LINE2=$(awk 'NR==2' $flag) LINE1=$(awk 'NR==1' $flag) FROM=${LINE3#*=} SENDER=${LINE2#*=} TO=${LINE1#*=} sendmail -F $SENDER -f $FROM -i $TO <