send email if restart failed

This commit is contained in:
Serghey Rodin 2013-08-07 11:50:00 +03:00
commit 44d78bbef6
7 changed files with 92 additions and 1 deletions

View file

@ -34,6 +34,19 @@ if [ ! -z "$CRON_SYSTEM" ]; then
if [ $? -ne 0 ]; then
/etc/init.d/$CRON_SYSTEM restart >/dev/null 2>&1
if [ $? -ne 0 ]; then
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
send_mail="$VESTA/web/inc/mail-wrapper.php"
else
send_mail=$(which mail)
fi
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
email=$(echo "$email" | cut -f 2 -d "'")
tmpfile=$(mktemp)
subj="$(hostname): $CRON_SYSTEM restart failed"
/etc/init.d/$CRON_SYSTEM configtest >> $tmpfile 2>&1
/etc/init.d/$CRON_SYSTEM restart >> $tmpfile 2>&1
cat $tmpfile | $send_mail -s "$subj" $email
rm -f $tmpfile
exit $E_RESTART
fi
fi

View file

@ -34,6 +34,19 @@ if [ ! -z "$DNS_SYSTEM" ]; then
if [ $? -ne 0 ]; then
/etc/init.d/$DNS_SYSTEM restart >/dev/null 2>&1
if [ $? -ne 0 ]; then
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
send_mail="$VESTA/web/inc/mail-wrapper.php"
else
send_mail=$(which mail)
fi
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
email=$(echo "$email" | cut -f 2 -d "'")
tmpfile=$(mktemp)
subj="$(hostname): $DNS_SYSTEM restart failed"
/etc/init.d/$DNS_SYSTEM configtest >> $tmpfile 2>&1
/etc/init.d/$DNS_SYSTEM restart >> $tmpfile 2>&1
cat $tmpfile | $send_mail -s "$subj" $email
rm -f $tmpfile
exit $E_RESTART
fi
fi

View file

@ -34,6 +34,19 @@ if [ ! -z "$FTP_SYSTEM" ]; then
if [ $? -ne 0 ]; then
/etc/init.d/$FTP_SYSTEM restart >/dev/null 2>&1
if [ $? -ne 0 ]; then
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
send_mail="$VESTA/web/inc/mail-wrapper.php"
else
send_mail=$(which mail)
fi
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
email=$(echo "$email" | cut -f 2 -d "'")
tmpfile=$(mktemp)
subj="$(hostname): $FTP_SYSTEM restart failed"
/etc/init.d/$FTP_SYSTEM configtest >> $tmpfile 2>&1
/etc/init.d/$FTP_SYSTEM restart >> $tmpfile 2>&1
cat $tmpfile | $send_mail -s "$subj" $email
rm -f $tmpfile
exit $E_RESTART
fi
fi

View file

@ -34,6 +34,19 @@ if [ ! -z "$MAIL_SYSTEM" ]; then
if [ $? -ne 0 ]; then
/etc/init.d/$MAIL_SYSTEM restart >/dev/null 2>&1
if [ $? -ne 0 ]; then
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
send_mail="$VESTA/web/inc/mail-wrapper.php"
else
send_mail=$(which mail)
fi
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
email=$(echo "$email" | cut -f 2 -d "'")
tmpfile=$(mktemp)
subj="$(hostname): $MAIL_SYSTEM restart failed"
/etc/init.d/$MAIL_SYSTEM configtest >> $tmpfile 2>&1
/etc/init.d/$MAIL_SYSTEM restart >> $tmpfile 2>&1
cat $tmpfile | $send_mail -s "$subj" $email
rm -f $tmpfile
exit $E_RESTART
fi
fi

View file

@ -34,6 +34,19 @@ if [ ! -z "$PROXY_SYSTEM" ]; then
if [ $? -ne 0 ]; then
/etc/init.d/$PROXY_SYSTEM restart >/dev/null 2>&1
if [ $? -ne 0 ]; then
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
send_mail="$VESTA/web/inc/mail-wrapper.php"
else
send_mail=$(which mail)
fi
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
email=$(echo "$email" | cut -f 2 -d "'")
tmpfile=$(mktemp)
subj="$(hostname): $PROXY_SYSTEM restart failed"
/etc/init.d/$PROXY_SYSTEM configtest >> $tmpfile 2>&1
/etc/init.d/$PROXY_SYSTEM restart >> $tmpfile 2>&1
cat $tmpfile | $send_mail -s "$subj" $email
rm -f $tmpfile
exit $E_RESTART
fi
fi

View file

@ -30,6 +30,19 @@ check_args '1' "$#" 'SERVICE'
if [ -x "/etc/init.d/$service" ]; then
/etc/init.d/$service restart >/dev/null 2>&1
if [ $? -ne 0 ]; then
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
send_mail="$VESTA/web/inc/mail-wrapper.php"
else
send_mail=$(which mail)
fi
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
email=$(echo "$email" | cut -f 2 -d "'")
tmpfile=$(mktemp)
subj="$(hostname): $service restart failed"
/etc/init.d/$service configtest >> $tmpfile 2>&1
/etc/init.d/$service restart >> $tmpfile 2>&1
cat $tmpfile | $send_mail -s "$subj" $email
rm -f $tmpfile
exit $E_RESTART
fi
fi

View file

@ -31,9 +31,22 @@ fi
# Restart system
if [ ! -z "$WEB_SYSTEM" ]; then
/etc/init.d/$WEB_SYSTEM reload >/dev/null 2>&1
if [ $? -ne 0 ]; then
if [ "$?" -ne 0 ]; then
/etc/init.d/$WEB_SYSTEM restart >/dev/null 2>&1
if [ $? -ne 0 ]; then
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
send_mail="$VESTA/web/inc/mail-wrapper.php"
else
send_mail=$(which mail)
fi
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
email=$(echo "$email" | cut -f 2 -d "'")
tmpfile=$(mktemp)
subj="$(hostname): $WEB_SYSTEM restart failed"
/etc/init.d/$WEB_SYSTEM configtest >> $tmpfile 2>&1
/etc/init.d/$WEB_SYSTEM restart >> $tmpfile 2>&1
cat $tmpfile | $send_mail -s "$subj" $email
rm -f $tmpfile
exit $E_RESTART
fi
fi