Skip to content

Commit 44d78bb

Browse files
committed
send email if restart failed
1 parent d430f14 commit 44d78bb

File tree

7 files changed

+92
-1
lines changed

7 files changed

+92
-1
lines changed

bin/v-restart-cron

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ if [ ! -z "$CRON_SYSTEM" ]; then
3434
if [ $? -ne 0 ]; then
3535
/etc/init.d/$CRON_SYSTEM restart >/dev/null 2>&1
3636
if [ $? -ne 0 ]; then
37+
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
38+
send_mail="$VESTA/web/inc/mail-wrapper.php"
39+
else
40+
send_mail=$(which mail)
41+
fi
42+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
43+
email=$(echo "$email" | cut -f 2 -d "'")
44+
tmpfile=$(mktemp)
45+
subj="$(hostname): $CRON_SYSTEM restart failed"
46+
/etc/init.d/$CRON_SYSTEM configtest >> $tmpfile 2>&1
47+
/etc/init.d/$CRON_SYSTEM restart >> $tmpfile 2>&1
48+
cat $tmpfile | $send_mail -s "$subj" $email
49+
rm -f $tmpfile
3750
exit $E_RESTART
3851
fi
3952
fi

bin/v-restart-dns

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ if [ ! -z "$DNS_SYSTEM" ]; then
3434
if [ $? -ne 0 ]; then
3535
/etc/init.d/$DNS_SYSTEM restart >/dev/null 2>&1
3636
if [ $? -ne 0 ]; then
37+
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
38+
send_mail="$VESTA/web/inc/mail-wrapper.php"
39+
else
40+
send_mail=$(which mail)
41+
fi
42+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
43+
email=$(echo "$email" | cut -f 2 -d "'")
44+
tmpfile=$(mktemp)
45+
subj="$(hostname): $DNS_SYSTEM restart failed"
46+
/etc/init.d/$DNS_SYSTEM configtest >> $tmpfile 2>&1
47+
/etc/init.d/$DNS_SYSTEM restart >> $tmpfile 2>&1
48+
cat $tmpfile | $send_mail -s "$subj" $email
49+
rm -f $tmpfile
3750
exit $E_RESTART
3851
fi
3952
fi

bin/v-restart-ftp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ if [ ! -z "$FTP_SYSTEM" ]; then
3434
if [ $? -ne 0 ]; then
3535
/etc/init.d/$FTP_SYSTEM restart >/dev/null 2>&1
3636
if [ $? -ne 0 ]; then
37+
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
38+
send_mail="$VESTA/web/inc/mail-wrapper.php"
39+
else
40+
send_mail=$(which mail)
41+
fi
42+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
43+
email=$(echo "$email" | cut -f 2 -d "'")
44+
tmpfile=$(mktemp)
45+
subj="$(hostname): $FTP_SYSTEM restart failed"
46+
/etc/init.d/$FTP_SYSTEM configtest >> $tmpfile 2>&1
47+
/etc/init.d/$FTP_SYSTEM restart >> $tmpfile 2>&1
48+
cat $tmpfile | $send_mail -s "$subj" $email
49+
rm -f $tmpfile
3750
exit $E_RESTART
3851
fi
3952
fi

bin/v-restart-mail

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ if [ ! -z "$MAIL_SYSTEM" ]; then
3434
if [ $? -ne 0 ]; then
3535
/etc/init.d/$MAIL_SYSTEM restart >/dev/null 2>&1
3636
if [ $? -ne 0 ]; then
37+
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
38+
send_mail="$VESTA/web/inc/mail-wrapper.php"
39+
else
40+
send_mail=$(which mail)
41+
fi
42+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
43+
email=$(echo "$email" | cut -f 2 -d "'")
44+
tmpfile=$(mktemp)
45+
subj="$(hostname): $MAIL_SYSTEM restart failed"
46+
/etc/init.d/$MAIL_SYSTEM configtest >> $tmpfile 2>&1
47+
/etc/init.d/$MAIL_SYSTEM restart >> $tmpfile 2>&1
48+
cat $tmpfile | $send_mail -s "$subj" $email
49+
rm -f $tmpfile
3750
exit $E_RESTART
3851
fi
3952
fi

bin/v-restart-proxy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ if [ ! -z "$PROXY_SYSTEM" ]; then
3434
if [ $? -ne 0 ]; then
3535
/etc/init.d/$PROXY_SYSTEM restart >/dev/null 2>&1
3636
if [ $? -ne 0 ]; then
37+
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
38+
send_mail="$VESTA/web/inc/mail-wrapper.php"
39+
else
40+
send_mail=$(which mail)
41+
fi
42+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
43+
email=$(echo "$email" | cut -f 2 -d "'")
44+
tmpfile=$(mktemp)
45+
subj="$(hostname): $PROXY_SYSTEM restart failed"
46+
/etc/init.d/$PROXY_SYSTEM configtest >> $tmpfile 2>&1
47+
/etc/init.d/$PROXY_SYSTEM restart >> $tmpfile 2>&1
48+
cat $tmpfile | $send_mail -s "$subj" $email
49+
rm -f $tmpfile
3750
exit $E_RESTART
3851
fi
3952
fi

bin/v-restart-service

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ check_args '1' "$#" 'SERVICE'
3030
if [ -x "/etc/init.d/$service" ]; then
3131
/etc/init.d/$service restart >/dev/null 2>&1
3232
if [ $? -ne 0 ]; then
33+
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
34+
send_mail="$VESTA/web/inc/mail-wrapper.php"
35+
else
36+
send_mail=$(which mail)
37+
fi
38+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
39+
email=$(echo "$email" | cut -f 2 -d "'")
40+
tmpfile=$(mktemp)
41+
subj="$(hostname): $service restart failed"
42+
/etc/init.d/$service configtest >> $tmpfile 2>&1
43+
/etc/init.d/$service restart >> $tmpfile 2>&1
44+
cat $tmpfile | $send_mail -s "$subj" $email
45+
rm -f $tmpfile
3346
exit $E_RESTART
3447
fi
3548
fi

bin/v-restart-web

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,22 @@ fi
3131
# Restart system
3232
if [ ! -z "$WEB_SYSTEM" ]; then
3333
/etc/init.d/$WEB_SYSTEM reload >/dev/null 2>&1
34-
if [ $? -ne 0 ]; then
34+
if [ "$?" -ne 0 ]; then
3535
/etc/init.d/$WEB_SYSTEM restart >/dev/null 2>&1
3636
if [ $? -ne 0 ]; then
37+
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
38+
send_mail="$VESTA/web/inc/mail-wrapper.php"
39+
else
40+
send_mail=$(which mail)
41+
fi
42+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
43+
email=$(echo "$email" | cut -f 2 -d "'")
44+
tmpfile=$(mktemp)
45+
subj="$(hostname): $WEB_SYSTEM restart failed"
46+
/etc/init.d/$WEB_SYSTEM configtest >> $tmpfile 2>&1
47+
/etc/init.d/$WEB_SYSTEM restart >> $tmpfile 2>&1
48+
cat $tmpfile | $send_mail -s "$subj" $email
49+
rm -f $tmpfile
3750
exit $E_RESTART
3851
fi
3952
fi

0 commit comments

Comments
 (0)