v-restart-web-backend 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. send_email_report() {
  13. email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
  14. email=$(echo "$email" | cut -f 2 -d "'")
  15. tmpfile=$(mktemp)
  16. subj="$(hostname): $WEB_BACKEND restart failed"
  17. service $WEB_BACKEND configtest >> $tmpfile 2>&1
  18. service $WEB_BACKEND restart >> $tmpfile 2>&1
  19. cat $tmpfile |$SENDMAIL -s "$subj" $email
  20. rm -f $tmpfile
  21. }
  22. #----------------------------------------------------------#
  23. # Action #
  24. #----------------------------------------------------------#
  25. # Schedule restart
  26. if [ "$1" = 'scheduled' ]; then
  27. echo "$BIN/$SCRIPT now" >> $VESTA/data/queue/restart.pipe
  28. exit
  29. fi
  30. if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
  31. echo "$BIN/$SCRIPT now" >> $VESTA/data/queue/restart.pipe
  32. exit
  33. fi
  34. if [ -z "$WEB_BACKEND" ] || [ "$WEB_BACKEND" = 'remote' ]; then
  35. exit
  36. fi
  37. # Restart system
  38. service $WEB_BACKEND restart >/dev/null 2>&1
  39. if [ $? -ne 0 ]; then
  40. send_email_report
  41. check_result $E_RESTART "$WEB_BACKEND restart failed"
  42. fi
  43. # Update restart queue
  44. if [ -e "$VESTA/data/queue/restart.pipe" ]; then
  45. sed -i "/$SCRIPT/d" $VESTA/data/queue/restart.pipe
  46. fi
  47. #----------------------------------------------------------#
  48. # Vesta #
  49. #----------------------------------------------------------#
  50. exit