v-restart-web-backend 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # info: restart backend server
  3. # options: NONE
  4. #
  5. # The function reloads backend server configuration.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Includes
  10. source $VESTA/func/main.sh
  11. source $VESTA/conf/vesta.conf
  12. PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin:/root/bin"
  13. send_email_report() {
  14. email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
  15. email=$(echo "$email" | cut -f 2 -d "'")
  16. tmpfile=$(mktemp)
  17. subj="$(hostname): $WEB_BACKEND restart failed"
  18. service $WEB_BACKEND configtest >> $tmpfile 2>&1
  19. service $WEB_BACKEND restart >> $tmpfile 2>&1
  20. cat $tmpfile |$SENDMAIL -s "$subj" $email
  21. rm -f $tmpfile
  22. }
  23. #----------------------------------------------------------#
  24. # Action #
  25. #----------------------------------------------------------#
  26. # Exit
  27. if [ "$1" = "no" ]; then
  28. exit
  29. fi
  30. # Schedule restart
  31. if [ "$1" = 'scheduled' ]; then
  32. echo "$BIN/$SCRIPT now" >> $VESTA/data/queue/restart.pipe
  33. exit
  34. fi
  35. if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
  36. echo "$BIN/$SCRIPT now" >> $VESTA/data/queue/restart.pipe
  37. exit
  38. fi
  39. if [ -z "$WEB_BACKEND" ] || [ "$WEB_BACKEND" = 'remote' ]; then
  40. exit
  41. fi
  42. # Restart system
  43. php_fpm=$(ls /etc/init.d/php*-fpm* 2>/dev/null |cut -f 4 -d /)
  44. if [ -z "$php_fpm" ]; then
  45. service $WEB_BACKEND restart >/dev/null 2>&1
  46. else
  47. service $php_fpm restart >/dev/null 2>&1
  48. fi
  49. if [ $? -ne 0 ]; then
  50. send_email_report
  51. check_result $E_RESTART "$WEB_BACKEND restart failed"
  52. fi
  53. # Update restart queue
  54. if [ -e "$VESTA/data/queue/restart.pipe" ]; then
  55. sed -i "/$SCRIPT/d" $VESTA/data/queue/restart.pipe
  56. fi
  57. #----------------------------------------------------------#
  58. # Vesta #
  59. #----------------------------------------------------------#
  60. exit