v-restart-proxy 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. # info: restart proxy server
  3. # options: NONE
  4. #
  5. # example: v-restart-proxy [RESTART]
  6. #
  7. # This function reloads proxy server configuration.
  8. #----------------------------------------------------------#
  9. # Variables & Functions #
  10. #----------------------------------------------------------#
  11. # Includes
  12. # shellcheck source=/etc/hestiacp/hestia.conf
  13. source /etc/hestiacp/hestia.conf
  14. # shellcheck source=/usr/local/hestia/func/main.sh
  15. source $HESTIA/func/main.sh
  16. # load config file
  17. source_conf "$HESTIA/conf/hestia.conf"
  18. date=$(date +"%Y-%m-%d %H:%M:%S");
  19. send_email_report() {
  20. email=$(grep CONTACT $HESTIA/data/users/admin/user.conf)
  21. email=$(echo "$email" | cut -f 2 -d "'")
  22. tmpfile=$(mktemp)
  23. subj="$(hostname): $PROXY_SYSTEM restart failed"
  24. nginx -t >> $tmpfile 2>&1
  25. service "$PROXY_SYSTEM" restart >> $tmpfile 2>&1
  26. cat "$tmpfile" |$SENDMAIL -s "$subj" "$email"
  27. if [ "$DEBUG_MODE" = "true" ]; then
  28. echo "[ $date | $PROXY_SYSTEM | PROXY ]" >> /var/log/hestia/debug.log 2>&1
  29. cat "$tmpfile" >> /var/log/hestia/debug.log 2>&1
  30. fi
  31. rm -f $tmpfile
  32. }
  33. #----------------------------------------------------------#
  34. # Action #
  35. #----------------------------------------------------------#
  36. # Exit
  37. if [ -z "$PROXY_SYSTEM" ] || [ "$PROXY_SYSTEM" = 'remote' ]; then
  38. exit
  39. fi
  40. if [ "$1" = "no" ]; then
  41. exit
  42. fi
  43. # Schedule restart
  44. if [ "$1" = 'scheduled' ] || [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
  45. sed -i "/\/$SCRIPT now/d" $HESTIA/data/queue/restart.pipe
  46. echo "$BIN/$SCRIPT now" >> $HESTIA/data/queue/restart.pipe
  47. exit
  48. fi
  49. if [ "$1" = "updatessl" ]; then
  50. sed -i "/\/$SCRIPT ssl/d" $HESTIA/data/queue/restart.pipe
  51. echo "$BIN/$SCRIPT ssl" >> $HESTIA/data/queue/restart.pipe
  52. exit
  53. fi
  54. if [ -f "$HESTIA/web/inc/nginx_proxy" ]; then
  55. # if hestia is behind default nginx, restart in background with 15 sec delay
  56. # background restart
  57. if [ "$1" = 'background' ]; then
  58. # Restart system
  59. sleep 15
  60. $BIN/v-restart-service $PROXY_SYSTEM > /dev/null 2>&1
  61. # Update restart queue
  62. if [ -e "$HESTIA/data/queue/restart.pipe" ]; then
  63. sed -i "/$SCRIPT/d" $HESTIA/data/queue/restart.pipe
  64. fi
  65. exit;
  66. fi
  67. # Send to background process
  68. nohup $BIN/v-restart-proxy 'background' &>/dev/null &
  69. else
  70. # Default behaviour
  71. # Preform an check if Nginx is valid as reload doesn't throw an error / exit
  72. if [ "$DEBUG_MODE" = "true" ]; then
  73. echo "[ $date | $PROXY_SYSTEM ]" >> /var/log/hestia/debug.log 2>&1
  74. service $PROXY_SYSTEM configtest >> /var/log/hestia/debug.log 2>&1
  75. else
  76. service $PROXY_SYSTEM configtest > /dev/null 2>&1
  77. fi
  78. if [ $? -ne 0 ]; then
  79. send_email_report
  80. check_result "$E_RESTART" "$PROXY_SYSTEM restart failed"
  81. fi
  82. # Restart system
  83. if [ "$1" = "ssl" ]; then
  84. restart="ssl"
  85. fi
  86. $BIN/v-restart-service "$PROXY_SYSTEM" "$restart" > /dev/null 2>&1
  87. # Update restart queue
  88. if [ -e "$HESTIA/data/queue/restart.pipe" ]; then
  89. sed -i "/\/$SCRIPT now/d" $HESTIA/data/queue/restart.pipe
  90. sed -i "/\/$SCRIPT ssl/d" $HESTIA/data/queue/restart.pipe
  91. fi
  92. fi
  93. #----------------------------------------------------------#
  94. # Hestia #
  95. #----------------------------------------------------------#
  96. exit