From 44d78bbef6313ff1e8c4a3e52c6bec6524f50e9f Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Wed, 7 Aug 2013 11:50:00 +0300 Subject: [PATCH] send email if restart failed --- bin/v-restart-cron | 13 +++++++++++++ bin/v-restart-dns | 13 +++++++++++++ bin/v-restart-ftp | 13 +++++++++++++ bin/v-restart-mail | 13 +++++++++++++ bin/v-restart-proxy | 13 +++++++++++++ bin/v-restart-service | 13 +++++++++++++ bin/v-restart-web | 15 ++++++++++++++- 7 files changed, 92 insertions(+), 1 deletion(-) diff --git a/bin/v-restart-cron b/bin/v-restart-cron index 86ef72cd..87223111 100755 --- a/bin/v-restart-cron +++ b/bin/v-restart-cron @@ -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 diff --git a/bin/v-restart-dns b/bin/v-restart-dns index 9fc0dbeb..40e78cf3 100755 --- a/bin/v-restart-dns +++ b/bin/v-restart-dns @@ -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 diff --git a/bin/v-restart-ftp b/bin/v-restart-ftp index a8e4d8a8..da106347 100755 --- a/bin/v-restart-ftp +++ b/bin/v-restart-ftp @@ -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 diff --git a/bin/v-restart-mail b/bin/v-restart-mail index c3c537f9..4afcd469 100755 --- a/bin/v-restart-mail +++ b/bin/v-restart-mail @@ -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 diff --git a/bin/v-restart-proxy b/bin/v-restart-proxy index 36363268..67e12cf7 100755 --- a/bin/v-restart-proxy +++ b/bin/v-restart-proxy @@ -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 diff --git a/bin/v-restart-service b/bin/v-restart-service index cf41b493..dfffab6b 100755 --- a/bin/v-restart-service +++ b/bin/v-restart-service @@ -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 diff --git a/bin/v-restart-web b/bin/v-restart-web index 337fbc2c..28bb73e0 100755 --- a/bin/v-restart-web +++ b/bin/v-restart-web @@ -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