Skip to content

Commit c2cf5e5

Browse files
authored
hestiacp#1779 Config test for Nginx / Apache2 before reload prevent issues where nginx / apache2 didn’t get reloaded due to an error in nginx config (hestiacp#1795)
1 parent 29f53fe commit c2cf5e5

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

bin/v-restart-proxy

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ send_email_report() {
2424
email=$(echo "$email" | cut -f 2 -d "'")
2525
tmpfile=$(mktemp)
2626
subj="$(hostname): $PROXY_SYSTEM restart failed"
27-
service $PROXY_SYSTEM configtest >> $tmpfile 2>&1
27+
nginx -t >> $tmpfile 2>&1
2828
service $PROXY_SYSTEM restart >> $tmpfile 2>&1
2929
cat $tmpfile |$SENDMAIL -s "$subj" $email
3030
rm -f $tmpfile
@@ -70,6 +70,14 @@ if [ -f "$HESTIA/web/inc/nginx_proxy" ]; then
7070
nohup $BIN/v-restart-proxy 'background' &>/dev/null &
7171
else
7272
# Default behaviour
73+
74+
# Preform an check if Nginx is valid as reload doesn't throw an error / exit
75+
result=$(service $WEB_SYSTEM $PROXY_SYSTEM >> /dev/null 2>&1 )
76+
if [ $? -ne 0 ]; then
77+
send_email_report
78+
check_result $E_RESTART "$PROXY_SYSTEM restart failed"
79+
fi
80+
7381
# Restart system
7482
$BIN/v-restart-service $PROXY_SYSTEM > /dev/null 2>&1
7583

bin/v-restart-web

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ send_email_report() {
2424
email=$(echo "$email" | cut -f 2 -d "'")
2525
tmpfile=$(mktemp)
2626
subj="$(hostname): $WEB_SYSTEM restart failed"
27-
service $WEB_SYSTEM configtest >> $tmpfile 2>&1
27+
if [ $WEB_SYSTEM = "apache2" ]; then
28+
apache2ctl configtest >> $tmpfile 2>&1
29+
else
30+
nginx -t >> $tmpfile 2>&1
31+
fi
2832
service $WEB_SYSTEM restart >> $tmpfile 2>&1
2933
cat $tmpfile |$SENDMAIL -s "$subj" $email
3034
rm -f $tmpfile
@@ -50,6 +54,19 @@ fi
5054
if [ -z "$WEB_SYSTEM" ] || [ "$WEB_SYSTEM" = 'remote' ]; then
5155
exit
5256
fi
57+
if [ $WEB_SYSTEM = 'nginx' ]; then
58+
result=$(service $WEB_SYSTEM configtest >> /dev/null 2>&1 )
59+
if [ $? -ne 0 ]; then
60+
send_email_report
61+
check_result $E_RESTART "$WEB_SYSTEM restart failed"
62+
fi
63+
elif [ $WEB_SYSTEM = 'apache2' ]; then
64+
result=$(apache2ctl configtest >> /dev/null 2>&1 )
65+
if [ $? -ne 0 ]; then
66+
send_email_report
67+
check_result $E_RESTART "$WEB_SYSTEM restart failed"
68+
fi
69+
fi
5370

5471
$BIN/v-restart-service $WEB_SYSTEM > /dev/null 2>&1
5572

0 commit comments

Comments
 (0)