Skip to content

Commit e7c9435

Browse files
committed
improved restart function
1 parent fd902a9 commit e7c9435

File tree

6 files changed

+140
-95
lines changed

6 files changed

+140
-95
lines changed

bin/v-restart-cron

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
source $VESTA/func/main.sh
1414
source $VESTA/conf/vesta.conf
1515

16+
send_email_report() {
17+
send_mail="$VESTA/web/inc/mail-wrapper.php"
18+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
19+
email=$(echo "$email" | cut -f 2 -d "'")
20+
tmpfile=$(mktemp)
21+
subj="$(hostname): $CRON_SYSTEM restart failed"
22+
/etc/init.d/$CRON_SYSTEM configtest >> $tmpfile 2>&1
23+
/etc/init.d/$CRON_SYSTEM restart >> $tmpfile 2>&1
24+
cat $tmpfile | $send_mail -s "$subj" $email
25+
rm -f $tmpfile
26+
}
27+
1628

1729
#----------------------------------------------------------#
1830
# Action #
@@ -28,23 +40,19 @@ if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
2840
exit
2941
fi
3042

43+
if [ -z "$CRON_SYSTEM" ]; then
44+
exit
45+
fi
46+
3147
# Restart system
32-
if [ ! -z "$CRON_SYSTEM" ]; then
48+
if [ -e "/var/run/crond.pid" ]; then
3349
/etc/init.d/$CRON_SYSTEM reload >/dev/null 2>&1
50+
reload cron >/dev/null 2>&1
51+
else
52+
/etc/init.d/$CRON_SYSTEM restart >/dev/null 2>&1
3453
if [ $? -ne 0 ]; then
35-
/etc/init.d/$CRON_SYSTEM restart >/dev/null 2>&1
36-
if [ $? -ne 0 ]; then
37-
send_mail="$VESTA/web/inc/mail-wrapper.php"
38-
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
39-
email=$(echo "$email" | cut -f 2 -d "'")
40-
tmpfile=$(mktemp)
41-
subj="$(hostname): $CRON_SYSTEM restart failed"
42-
/etc/init.d/$CRON_SYSTEM configtest >> $tmpfile 2>&1
43-
/etc/init.d/$CRON_SYSTEM restart >> $tmpfile 2>&1
44-
cat $tmpfile | $send_mail -s "$subj" $email
45-
rm -f $tmpfile
46-
exit $E_RESTART
47-
fi
54+
send_email_report
55+
exit $E_RESTART
4856
fi
4957
fi
5058

bin/v-restart-dns

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@
1313
source $VESTA/func/main.sh
1414
source $VESTA/conf/vesta.conf
1515

16+
send_email_report() {
17+
if [ -e '/etc/named.conf' ]; then
18+
dns_conf='/etc/named.conf'
19+
else
20+
dns_conf='/etc/bind/named.conf'
21+
fi
22+
23+
send_mail="$VESTA/web/inc/mail-wrapper.php"
24+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
25+
email=$(echo "$email" | cut -f 2 -d "'")
26+
tmpfile=$(mktemp)
27+
subj="$(hostname): $DNS_SYSTEM restart failed"
28+
named-checkconf $dns_conf >> $tmpfile 2>&1
29+
/etc/init.d/$DNS_SYSTEM restart >> $tmpfile 2>&1
30+
cat $tmpfile | $send_mail -s "$subj" $email
31+
rm -f $tmpfile
32+
}
33+
1634

1735
#----------------------------------------------------------#
1836
# Action #
@@ -28,30 +46,17 @@ if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
2846
exit
2947
fi
3048

49+
if [ -z "$DNS_SYSTEM" ]; then
50+
exit
51+
fi
52+
3153
# Restart system
32-
if [ ! -z "$DNS_SYSTEM" ]; then
33-
/etc/init.d/$DNS_SYSTEM reload >/dev/null 2>&1
54+
/etc/init.d/$DNS_SYSTEM reload >/dev/null 2>&1
55+
if [ $? -ne 0 ]; then
56+
/etc/init.d/$DNS_SYSTEM restart >/dev/null 2>&1
3457
if [ $? -ne 0 ]; then
35-
/etc/init.d/$DNS_SYSTEM restart >/dev/null 2>&1
36-
if [ $? -ne 0 ]; then
37-
send_mail="$VESTA/web/inc/mail-wrapper.php"
38-
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
39-
email=$(echo "$email" | cut -f 2 -d "'")
40-
tmpfile=$(mktemp)
41-
subj="$(hostname): $DNS_SYSTEM restart failed"
42-
43-
# Get dns config path
44-
if [ -e '/etc/named.conf' ]; then
45-
dns_conf='/etc/named.conf'
46-
else
47-
dns_conf='/etc/bind/named.conf'
48-
fi
49-
named-checkconf $dns_conf >> $tmpfile 2>&1
50-
/etc/init.d/$DNS_SYSTEM restart >> $tmpfile 2>&1
51-
cat $tmpfile | $send_mail -s "$subj" $email
52-
rm -f $tmpfile
53-
exit $E_RESTART
54-
fi
58+
send_email_report
59+
exit $E_RESTART
5560
fi
5661
fi
5762

bin/v-restart-ftp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
source $VESTA/func/main.sh
1414
source $VESTA/conf/vesta.conf
1515

16+
send_email_report() {
17+
send_mail="$VESTA/web/inc/mail-wrapper.php"
18+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
19+
email=$(echo "$email" | cut -f 2 -d "'")
20+
tmpfile=$(mktemp)
21+
subj="$(hostname): $FTP_SYSTEM restart failed"
22+
/etc/init.d/$FTP_SYSTEM configtest >> $tmpfile 2>&1
23+
/etc/init.d/$FTP_SYSTEM restart >> $tmpfile 2>&1
24+
cat $tmpfile | $send_mail -s "$subj" $email
25+
rm -f $tmpfile
26+
}
27+
1628

1729
#----------------------------------------------------------#
1830
# Action #
@@ -28,24 +40,15 @@ if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
2840
exit
2941
fi
3042

43+
if [ -z "$FTP_SYSTEM" ]; then
44+
exit
45+
fi
46+
3147
# Restart system
32-
if [ ! -z "$FTP_SYSTEM" ]; then
33-
/etc/init.d/$FTP_SYSTEM reload >/dev/null 2>&1
34-
if [ $? -ne 0 ]; then
35-
/etc/init.d/$FTP_SYSTEM restart >/dev/null 2>&1
36-
if [ $? -ne 0 ]; then
37-
send_mail="$VESTA/web/inc/mail-wrapper.php"
38-
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
39-
email=$(echo "$email" | cut -f 2 -d "'")
40-
tmpfile=$(mktemp)
41-
subj="$(hostname): $FTP_SYSTEM restart failed"
42-
/etc/init.d/$FTP_SYSTEM configtest >> $tmpfile 2>&1
43-
/etc/init.d/$FTP_SYSTEM restart >> $tmpfile 2>&1
44-
cat $tmpfile | $send_mail -s "$subj" $email
45-
rm -f $tmpfile
46-
exit $E_RESTART
47-
fi
48-
fi
48+
/etc/init.d/$FTP_SYSTEM restart >/dev/null 2>&1
49+
if [ $? -ne 0 ]; then
50+
send_email_report
51+
exit $E_RESTART
4952
fi
5053

5154
# Update restart queue

bin/v-restart-mail

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
source $VESTA/func/main.sh
1414
source $VESTA/conf/vesta.conf
1515

16+
send_email_report() {
17+
send_mail="$VESTA/web/inc/mail-wrapper.php"
18+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
19+
email=$(echo "$email" | cut -f 2 -d "'")
20+
tmpfile=$(mktemp)
21+
subj="$(hostname): $MAIL_SYSTEM restart failed"
22+
/etc/init.d/$MAIL_SYSTEM configtest >> $tmpfile 2>&1
23+
/etc/init.d/$MAIL_SYSTEM restart >> $tmpfile 2>&1
24+
cat $tmpfile | $send_mail -s "$subj" $email
25+
rm -f $tmpfile
26+
}
27+
1628

1729
#----------------------------------------------------------#
1830
# Action #
@@ -28,24 +40,16 @@ if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
2840
exit
2941
fi
3042

43+
44+
if [ -z "$MAIL_SYSTEM" ]; then
45+
exit
46+
fi
47+
3148
# Restart system
32-
if [ ! -z "$MAIL_SYSTEM" ]; then
33-
/etc/init.d/$MAIL_SYSTEM reload >/dev/null 2>&1
34-
if [ $? -ne 0 ]; then
35-
/etc/init.d/$MAIL_SYSTEM restart >/dev/null 2>&1
36-
if [ $? -ne 0 ]; then
37-
send_mail="$VESTA/web/inc/mail-wrapper.php"
38-
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
39-
email=$(echo "$email" | cut -f 2 -d "'")
40-
tmpfile=$(mktemp)
41-
subj="$(hostname): $MAIL_SYSTEM restart failed"
42-
/etc/init.d/$MAIL_SYSTEM configtest >> $tmpfile 2>&1
43-
/etc/init.d/$MAIL_SYSTEM restart >> $tmpfile 2>&1
44-
cat $tmpfile | $send_mail -s "$subj" $email
45-
rm -f $tmpfile
46-
exit $E_RESTART
47-
fi
48-
fi
49+
/etc/init.d/$MAIL_SYSTEM restart >/dev/null 2>&1
50+
if [ $? -ne 0 ]; then
51+
send_email_report
52+
exit $E_RESTART
4953
fi
5054

5155
# Update restart queue

bin/v-restart-proxy

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
source $VESTA/func/main.sh
1414
source $VESTA/conf/vesta.conf
1515

16+
send_email_report() {
17+
send_mail="$VESTA/web/inc/mail-wrapper.php"
18+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
19+
email=$(echo "$email" | cut -f 2 -d "'")
20+
tmpfile=$(mktemp)
21+
subj="$(hostname): $PROXY_SYSTEM restart failed"
22+
/etc/init.d/$PROXY_SYSTEM configtest >> $tmpfile 2>&1
23+
/etc/init.d/$PROXY_SYSTEM restart >> $tmpfile 2>&1
24+
cat $tmpfile | $send_mail -s "$subj" $email
25+
rm -f $tmpfile
26+
}
27+
1628

1729
#----------------------------------------------------------#
1830
# Action #
@@ -28,23 +40,17 @@ if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
2840
exit
2941
fi
3042

43+
if [ -z "$PROXY_SYSTEM" ]; then
44+
exit
45+
fi
46+
3147
# Restart system
32-
if [ ! -z "$PROXY_SYSTEM" ]; then
33-
/etc/init.d/$PROXY_SYSTEM reload >/dev/null 2>&1
48+
/etc/init.d/$PROXY_SYSTEM reload >/dev/null 2>&1
49+
if [ $? -ne 0 ]; then
50+
/etc/init.d/$PROXY_SYSTEM restart >/dev/null 2>&1
3451
if [ $? -ne 0 ]; then
35-
/etc/init.d/$PROXY_SYSTEM restart >/dev/null 2>&1
36-
if [ $? -ne 0 ]; then
37-
send_mail="$VESTA/web/inc/mail-wrapper.php"
38-
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
39-
email=$(echo "$email" | cut -f 2 -d "'")
40-
tmpfile=$(mktemp)
41-
subj="$(hostname): $PROXY_SYSTEM restart failed"
42-
/etc/init.d/$PROXY_SYSTEM configtest >> $tmpfile 2>&1
43-
/etc/init.d/$PROXY_SYSTEM restart >> $tmpfile 2>&1
44-
cat $tmpfile | $send_mail -s "$subj" $email
45-
rm -f $tmpfile
46-
exit $E_RESTART
47-
fi
52+
send_email_report
53+
exit $E_RESTART
4854
fi
4955
fi
5056

bin/v-restart-web

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
source $VESTA/func/main.sh
1414
source $VESTA/conf/vesta.conf
1515

16+
send_email_report() {
17+
send_mail="$VESTA/web/inc/mail-wrapper.php"
18+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
19+
email=$(echo "$email" | cut -f 2 -d "'")
20+
tmpfile=$(mktemp)
21+
subj="$(hostname): $WEB_SYSTEM restart failed"
22+
/etc/init.d/$WEB_SYSTEM configtest >> $tmpfile 2>&1
23+
/etc/init.d/$WEB_SYSTEM restart >> $tmpfile 2>&1
24+
cat $tmpfile | $send_mail -s "$subj" $email
25+
rm -f $tmpfile
26+
}
27+
1628

1729
#----------------------------------------------------------#
1830
# Action #
@@ -28,21 +40,28 @@ if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
2840
exit
2941
fi
3042

43+
44+
if [ -z "$WEB_SYSTEM" ]; then
45+
exit
46+
fi
47+
3148
# Restart system
32-
if [ ! -z "$WEB_SYSTEM" ]; then
49+
if [ "$WEB_SYSTEM" == 'apache2' ]; then
50+
if [ -e "/var/run/apache2.pid" ]; then
51+
/etc/init.d/$WEB_SYSTEM reload >/dev/null 2>&1
52+
else
53+
/etc/init.d/$WEB_SYSTEM restart >/dev/null 2>&1
54+
if [ $? -ne 0 ]; then
55+
send_email_report
56+
exit $E_RESTART
57+
fi
58+
fi
59+
else
3360
/etc/init.d/$WEB_SYSTEM reload >/dev/null 2>&1
3461
if [ "$?" -ne 0 ]; then
3562
/etc/init.d/$WEB_SYSTEM restart >/dev/null 2>&1
3663
if [ $? -ne 0 ]; then
37-
send_mail="$VESTA/web/inc/mail-wrapper.php"
38-
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
39-
email=$(echo "$email" | cut -f 2 -d "'")
40-
tmpfile=$(mktemp)
41-
subj="$(hostname): $WEB_SYSTEM restart failed"
42-
/etc/init.d/$WEB_SYSTEM configtest >> $tmpfile 2>&1
43-
/etc/init.d/$WEB_SYSTEM restart >> $tmpfile 2>&1
44-
cat $tmpfile | $send_mail -s "$subj" $email
45-
rm -f $tmpfile
64+
send_email_report
4665
exit $E_RESTART
4766
fi
4867
fi

0 commit comments

Comments
 (0)