Переглянути джерело

send email if restart failed

Serghey Rodin 12 роки тому
батько
коміт
44d78bbef6
7 змінених файлів з 92 додано та 1 видалено
  1. 13 0
      bin/v-restart-cron
  2. 13 0
      bin/v-restart-dns
  3. 13 0
      bin/v-restart-ftp
  4. 13 0
      bin/v-restart-mail
  5. 13 0
      bin/v-restart-proxy
  6. 13 0
      bin/v-restart-service
  7. 14 1
      bin/v-restart-web

+ 13 - 0
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

+ 13 - 0
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

+ 13 - 0
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

+ 13 - 0
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

+ 13 - 0
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

+ 13 - 0
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

+ 14 - 1
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