| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #!/bin/bash
- # info: restart proxy server
- # options: NONE
- #
- # example: v-restart-proxy [RESTART]
- #
- # This function reloads proxy server configuration.
- #----------------------------------------------------------#
- # Variables & Functions #
- #----------------------------------------------------------#
- # Includes
- # shellcheck source=/etc/hestiacp/hestia.conf
- source /etc/hestiacp/hestia.conf
- # shellcheck source=/usr/local/hestia/func/main.sh
- source $HESTIA/func/main.sh
- # load config file
- source_conf "$HESTIA/conf/hestia.conf"
- date=$(date +"%Y-%m-%d %H:%M:%S");
- send_email_report() {
- email=$(grep CONTACT $HESTIA/data/users/admin/user.conf)
- email=$(echo "$email" | cut -f 2 -d "'")
- tmpfile=$(mktemp)
- subj="$(hostname): $PROXY_SYSTEM restart failed"
- nginx -t >> $tmpfile 2>&1
- service "$PROXY_SYSTEM" restart >> $tmpfile 2>&1
- cat "$tmpfile" |$SENDMAIL -s "$subj" "$email"
- if [ "$DEBUG_MODE" = "true" ]; then
- echo "[ $date | $PROXY_SYSTEM | PROXY ]" >> /var/log/hestia/debug.log 2>&1
- cat "$tmpfile" >> /var/log/hestia/debug.log 2>&1
- fi
- rm -f $tmpfile
- }
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Exit
- if [ -z "$PROXY_SYSTEM" ] || [ "$PROXY_SYSTEM" = 'remote' ]; then
- exit
- fi
- if [ "$1" = "no" ]; then
- exit
- fi
- # Schedule restart
- if [ "$1" = 'scheduled' ] || [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
- sed -i "/\/$SCRIPT now/d" $HESTIA/data/queue/restart.pipe
- echo "$BIN/$SCRIPT now" >> $HESTIA/data/queue/restart.pipe
- exit
- fi
- if [ "$1" = "updatessl" ]; then
- sed -i "/\/$SCRIPT ssl/d" $HESTIA/data/queue/restart.pipe
- echo "$BIN/$SCRIPT ssl" >> $HESTIA/data/queue/restart.pipe
- exit
- fi
- if [ -f "$HESTIA/web/inc/nginx_proxy" ]; then
- # if hestia is behind default nginx, restart in background with 15 sec delay
- # background restart
- if [ "$1" = 'background' ]; then
- # Restart system
- sleep 15
- $BIN/v-restart-service $PROXY_SYSTEM > /dev/null 2>&1
- # Update restart queue
- if [ -e "$HESTIA/data/queue/restart.pipe" ]; then
- sed -i "/$SCRIPT/d" $HESTIA/data/queue/restart.pipe
- fi
- exit;
- fi
- # Send to background process
- nohup $BIN/v-restart-proxy 'background' &>/dev/null &
- else
- # Default behaviour
-
- # Preform an 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
- # Restart system
- if [ "$1" = "ssl" ]; then
- restart="ssl"
- fi
- $BIN/v-restart-service "$PROXY_SYSTEM" "$restart" > /dev/null 2>&1
- # Update restart queue
- if [ -e "$HESTIA/data/queue/restart.pipe" ]; then
- sed -i "/\/$SCRIPT now/d" $HESTIA/data/queue/restart.pipe
- sed -i "/\/$SCRIPT ssl/d" $HESTIA/data/queue/restart.pipe
- fi
- fi
- #----------------------------------------------------------#
- # Hestia #
- #----------------------------------------------------------#
- exit
|