Skip to content

Commit ef88a79

Browse files
Improve logging for services (hestiacp#2701)
* Improve logging for services In current system we are in a block box if there is an issue with the configs. When DEBUG_MODE is enabled it will save the out put of - Config tests (Proxy and web) - Output of v-restart-services Hopefully it will provide with some more information * Add check for debug mode before logging * Move date function * Revert, my bad. Co-authored-by: Raphael <rs@scit.ch>
1 parent 570b5dd commit ef88a79

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

bin/v-restart-proxy

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ source $HESTIA/func/main.sh
1818
# load config file
1919
source_conf "$HESTIA/conf/hestia.conf"
2020

21+
date=$(date +"%Y-%m-%d %H:%M:%S");
22+
2123
send_email_report() {
2224
email=$(grep CONTACT $HESTIA/data/users/admin/user.conf)
2325
email=$(echo "$email" | cut -f 2 -d "'")
@@ -26,6 +28,10 @@ send_email_report() {
2628
nginx -t >> $tmpfile 2>&1
2729
service "$PROXY_SYSTEM" restart >> $tmpfile 2>&1
2830
cat "$tmpfile" |$SENDMAIL -s "$subj" "$email"
31+
if [ "$DEBUG_MODE" = "true" ]; then
32+
echo "[ $date | $PROXY_SYSTEM | PROXY ]" >> /var/log/hestia/debug.log 2>&1
33+
cat "$tmpfile" >> /var/log/hestia/debug.log 2>&1
34+
fi
2935
rm -f $tmpfile
3036
}
3137

@@ -76,7 +82,12 @@ if [ -f "$HESTIA/web/inc/nginx_proxy" ]; then
7682
# Default behaviour
7783

7884
# Preform an check if Nginx is valid as reload doesn't throw an error / exit
79-
service $PROXY_SYSTEM configtest > /dev/null 2>&1
85+
if [ "$DEBUG_MODE" = "true" ]; then
86+
echo "[ $date | $PROXY_SYSTEM ]" >> /var/log/hestia/debug.log 2>&1
87+
service $PROXY_SYSTEM configtest > /var/log/hestia/debug.log 2>&1
88+
else
89+
service $PROXY_SYSTEM configtest > /dev/null 2>&1
90+
fi
8091
if [ $? -ne 0 ]; then
8192
send_email_report
8293
check_result "$E_RESTART" "$PROXY_SYSTEM restart failed"

bin/v-restart-service

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ is_format_valid 'service' 'restart'
3131
# Action #
3232
#----------------------------------------------------------#
3333

34+
log="/dev/null"
35+
if [ "$DEBUG_MODE" = "true" ]; then
36+
37+
log="/var/log/hestia/debug.log"
38+
fi
39+
3440
# Multi-instance service restart request handling
3541
if [ "$service" = "php-fpm" ];then
3642
service_list=''
@@ -51,7 +57,7 @@ for service in $service_list; do
5157
$BIN/v-stop-firewall
5258
$BIN/v-update-firewall
5359
elif [ "$restart" = "ssl" ] && [ "$service" = "nginx" ]; then
54-
service $service upgrade > /dev/null 2>&1
60+
service $service upgrade >> $log 2>&1
5561
elif [ -z "$restart" -o "$restart" = "no" ] && [ \
5662
"$service" = "nginx" -o \
5763
"$service" = "apache2" -o \
@@ -73,8 +79,8 @@ for service in $service_list; do
7379
"$service" = "fail2ban" ]; then
7480
systemctl reload-or-restart "$service" > /dev/null 2>&1
7581
else
76-
systemctl reset-failed "$service "> /dev/null 2>&1
77-
systemctl restart "$service" > /dev/null 2>&1
82+
systemctl reset-failed "$service" >> $log 2>&1
83+
systemctl restart "$service" >> $log 2>&1
7884
fi
7985

8086
# Check the result of the service restart and report whether it failed.

bin/v-restart-web

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ source $HESTIA/func/main.sh
1818
# load config file
1919
source_conf "$HESTIA/conf/hestia.conf"
2020

21+
date=$(date +"%Y-%m-%d %H:%M:%S");
22+
2123
send_email_report() {
2224
email=$(grep CONTACT $HESTIA/data/users/admin/user.conf)
2325
email=$(echo "$email" | cut -f 2 -d "'")
@@ -26,10 +28,14 @@ send_email_report() {
2628
if [ "$WEB_SYSTEM" = "apache2" ]; then
2729
apache2ctl configtest >> "$tmpfile" 2>&1
2830
else
29-
nginx -t >> $tmpfile 2>&1
31+
service $WEB_SYSTEM configtest >> "$tmpfile" 2>&1
3032
fi
3133
service "$WEB_SYSTEM" restart >> "$tmpfile" 2>&1
3234
cat "$tmpfile" |$SENDMAIL -s "$subj" "$email"
35+
if [ "$DEBUG_MODE" = "true" ]; then
36+
echo "[ $date | $WEB_SYSTEM | WEB ]" >> /var/log/hestia/debug.log 2>&1
37+
cat $tmpfile >> /var/log/hestia/debug.log 2>&1
38+
fi
3339
rm -f $tmpfile
3440
}
3541

@@ -64,13 +70,23 @@ if [ $WEB_SYSTEM = 'nginx' ]; then
6470
if [ "$1" = "ssl" ]; then
6571
restart="ssl"
6672
fi
67-
service $WEB_SYSTEM configtest > /dev/null 2>&1
73+
if [ "$DEBUG_MODE" = "true" ]; then
74+
echo "[ $date | $WEB_SYSTEM | WEB ]" >> /var/log/hestia/debug.log 2>&1
75+
service $WEB_SYSTEM configtest >> /var/log/hestia/debug.log 2>&1
76+
else
77+
service $WEB_SYSTEM configtest > /dev/null 2>&1
78+
fi
6879
if [ $? -ne 0 ]; then
6980
send_email_report
7081
check_result "$E_RESTART" "$WEB_SYSTEM restart failed"
7182
fi
7283
elif [ $WEB_SYSTEM = 'apache2' ]; then
73-
apache2ctl configtest > /dev/null 2>&1
84+
if [ "$DEBUG_MODE" = "true" ]; then
85+
echo "[ $date | $WEB_SYSTEM | WEB ]" >> /var/log/hestia/debug.log 2>&1
86+
apache2ctl configtest >> /var/log/hestia/debug.log 2>&1
87+
else
88+
apache2ctl configtest > /dev/null 2>&1
89+
fi
7490
if [ $? -ne 0 ]; then
7591
send_email_report
7692
check_result "$E_RESTART" "$WEB_SYSTEM restart failed"

0 commit comments

Comments
 (0)