Преглед изворни кода

Add config to avoid restarting daemons on error (#3183)

* Replace configuration with flag

When able, `send_email_report` accepts a flag to restart the service
only if it has already failed to restart.
Joel Kuhn пре 3 година
родитељ
комит
d2f918968b
3 измењених фајлова са 42 додато и 6 уклоњено
  1. 16 2
      bin/v-restart-dns
  2. 22 2
      bin/v-restart-proxy
  3. 4 2
      bin/v-restart-web

+ 16 - 2
bin/v-restart-dns

@@ -29,7 +29,9 @@ send_email_report() {
 	tmpfile=$(mktemp)
 	subj="$(hostname): "$DNS_SYSTEM" restart failed"
 	/usr/sbin/named-checkconf "$dns_conf" >> $tmpfile 2>&1
-	service "$DNS_SYSTEM" restart >> $tmpfile 2>&1
+	if [ "$1" == "DO_RESTART" ]; then
+		service "$DNS_SYSTEM" restart >> $tmpfile 2>&1
+	fi
 	cat $tmpfile | $SENDMAIL -s "$subj" $email
 	rm -f $tmpfile
 }
@@ -54,10 +56,22 @@ if [ "$1" = 'scheduled' ] || [ -z "$1" -a "$SCHEDULED_RESTART" = 'yes' ]; then
 	exit
 fi
 
+
+if [ -e '/etc/named.conf' ]; then
+	dns_conf='/etc/named.conf'
+else
+	dns_conf='/etc/bind/named.conf'
+fi
+/usr/sbin/named-checkconf "$dns_conf" > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	send_email_report
+	check_result "$E_RESTART" "$DNS_SYSTEM restart failed'"
+fi
+
 # Restart system
 $BIN/v-restart-service "$DNS_SYSTEM" "$1" > /dev/null 2>&1
 if [ $? -ne 0 ]; then
-	send_email_report
+	send_email_report "DO_RESTART"
 	check_result "$E_RESTART" "$DNS_SYSTEM restart failed"
 fi
 

+ 22 - 2
bin/v-restart-proxy

@@ -26,7 +26,10 @@ send_email_report() {
 	tmpfile=$(mktemp)
 	subj="$(hostname): $PROXY_SYSTEM restart failed"
 	nginx -t >> $tmpfile 2>&1
-	service "$PROXY_SYSTEM" restart >> $tmpfile 2>&1
+
+	if [ "$1" == "DO_RESTART" ]; then
+		service "$PROXY_SYSTEM" restart >> $tmpfile 2>&1
+	fi
 	cat "$tmpfile" | $SENDMAIL -s "$subj" "$email"
 	if [ "$DEBUG_MODE" = "true" ]; then
 		echo "[ $date | $PROXY_SYSTEM | PROXY ]" >> /var/log/hestia/debug.log 2>&1
@@ -67,6 +70,19 @@ if [ -f "$HESTIA/web/inc/nginx_proxy" ]; then
 	if [ "$1" = 'background' ]; then
 		# Restart system
 		sleep 15
+
+		# Preform a check if Nginx is valid as reload doesn't throw an error / exit
+		if [ "$DEBUG_MODE" = "true" ]; then
+			echo "[ $date | $PROXY_SYSTEM ]" >> /var/log/hestia/debug.log 2>&1
+			service $PROXY_SYSTEM configtest >> /var/log/hestia/debug.log 2>&1
+		else
+			service $PROXY_SYSTEM configtest > /dev/null 2>&1
+		fi
+		if [ $? -ne 0 ]; then
+			send_email_report
+			check_result "$E_RESTART" "$PROXY_SYSTEM restart failed"
+		fi
+
 		$BIN/v-restart-service $PROXY_SYSTEM > /dev/null 2>&1
 
 		# Update restart queue
@@ -81,7 +97,7 @@ if [ -f "$HESTIA/web/inc/nginx_proxy" ]; then
 else
 	# Default behaviour
 
-	# Preform an check if Nginx is valid as reload doesn't throw an error / exit
+	# Preform a check if Nginx is valid as reload doesn't throw an error / exit
 	if [ "$DEBUG_MODE" = "true" ]; then
 		echo "[ $date | $PROXY_SYSTEM ]" >> /var/log/hestia/debug.log 2>&1
 		service $PROXY_SYSTEM configtest >> /var/log/hestia/debug.log 2>&1
@@ -98,6 +114,10 @@ else
 		restart="ssl"
 	fi
 	$BIN/v-restart-service "$PROXY_SYSTEM" "$restart" > /dev/null 2>&1
+	if [ $? -ne 0 ]; then
+		send_email_report "DO_RESTART"
+		check_result "$E_RESTART" "$PROXY_SYSTEM restart failed"
+	fi
 
 	# Update restart queue
 	if [ -e "$HESTIA/data/queue/restart.pipe" ]; then

+ 4 - 2
bin/v-restart-web

@@ -30,7 +30,9 @@ send_email_report() {
 	else
 		service $WEB_SYSTEM configtest >> "$tmpfile" 2>&1
 	fi
-	service "$WEB_SYSTEM" restart >> "$tmpfile" 2>&1
+	if [ "$1" == "DO_RESTART" ]; then
+		service "$WEB_SYSTEM" restart >> "$tmpfile" 2>&1
+	fi
 	cat "$tmpfile" | $SENDMAIL -s "$subj" "$email"
 	if [ "$DEBUG_MODE" = "true" ]; then
 		echo "[ $date | $WEB_SYSTEM | WEB ]" >> /var/log/hestia/debug.log 2>&1
@@ -96,7 +98,7 @@ fi
 $BIN/v-restart-service "$WEB_SYSTEM" "$restart"
 
 if [ $? -ne 0 ]; then
-	send_email_report
+	send_email_report "DO_RESTART"
 	check_result "$E_RESTART" "$WEB_SYSTEM restart failed"
 fi