mirror of
https://github.com/myvesta/vesta.git
synced 2024-12-21 11:31:21 -08:00
103 lines
2.7 KiB
Bash
103 lines
2.7 KiB
Bash
#!/bin/bash
|
|
# info: restart proxy server
|
|
# options: NONE
|
|
#
|
|
# The function reloads proxy server configuration.
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Variable&Function #
|
|
#----------------------------------------------------------#
|
|
|
|
# Includes
|
|
source $VESTA/func/main.sh
|
|
source $VESTA/conf/vesta.conf
|
|
PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin:/root/bin"
|
|
|
|
send_email_report() {
|
|
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
|
|
email=$(echo "$email" | cut -f 2 -d "'")
|
|
tmpfile=$(mktemp)
|
|
subj="$(hostname): $PROXY_SYSTEM restart failed"
|
|
service $PROXY_SYSTEM configtest >> $tmpfile 2>&1
|
|
service $PROXY_SYSTEM restart >> $tmpfile 2>&1
|
|
cat $tmpfile |$SENDMAIL -s "$subj" $email
|
|
rm -f $tmpfile
|
|
}
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
|
|
# Exit
|
|
if [ "$1" = "no" ]; then
|
|
exit
|
|
fi
|
|
|
|
# Schedule restart
|
|
if [ "$1" = 'scheduled' ]; then
|
|
echo "$BIN/$SCRIPT now" >> $VESTA/data/queue/restart.pipe
|
|
exit
|
|
fi
|
|
if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
|
|
echo "$BIN/$SCRIPT now" >> $VESTA/data/queue/restart.pipe
|
|
exit
|
|
fi
|
|
|
|
if [ -z "$PROXY_SYSTEM" ] || [ "$PROXY_SYSTEM" = 'remote' ]; then
|
|
exit
|
|
fi
|
|
|
|
if [ -f "/usr/local/vesta/web/inc/nginx_proxy" ]; then
|
|
|
|
# if vesta is behind default nginx, restart in background with 15 sec delay
|
|
# background restart
|
|
if [ "$1" = 'background' ]; then
|
|
# Restart system
|
|
sleep 25
|
|
service $PROXY_SYSTEM restart >/dev/null 2>&1
|
|
if [ $? -ne 0 ]; then
|
|
send_email_report
|
|
check_result $E_RESTART "$PROXY_SYSTEM restart failed"
|
|
fi
|
|
|
|
# Update restart queue
|
|
if [ -e "$VESTA/data/queue/restart.pipe" ]; then
|
|
sed -i "/$SCRIPT/d" $VESTA/data/queue/restart.pipe
|
|
fi
|
|
|
|
exit;
|
|
fi
|
|
|
|
# try to reload to get changes faster
|
|
service $PROXY_SYSTEM reload
|
|
|
|
# send to background process
|
|
nohup $BIN/v-restart-proxy 'background' &>/dev/null &
|
|
|
|
else
|
|
|
|
# Default behaviour
|
|
# Restart system
|
|
# service $PROXY_SYSTEM restart > /dev/null 2>&1
|
|
systemctl reset-failed $PROXY_SYSTEM
|
|
systemctl restart $PROXY_SYSTEM > /dev/null 2>&1
|
|
if [ $? -ne 0 ]; then
|
|
send_email_report
|
|
check_result $E_RESTART "$PROXY_SYSTEM restart failed"
|
|
fi
|
|
|
|
# Update restart queue
|
|
if [ -e "$VESTA/data/queue/restart.pipe" ]; then
|
|
sed -i "/$SCRIPT/d" $VESTA/data/queue/restart.pipe
|
|
fi
|
|
|
|
fi
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
exit
|