v-restart-web-backend 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. # Schedule restart
  27. if [ "$1" = 'scheduled' ]; then
  28. echo "$BIN/$SCRIPT now" >> $VESTA/data/queue/restart.pipe
  29. exit
  30. fi
  31. if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
  32. echo "$BIN/$SCRIPT now" >> $VESTA/data/queue/restart.pipe
  33. exit
  34. fi
  35. if [ -z "$WEB_BACKEND" ] || [ "$WEB_BACKEND" = 'remote' ]; then
  36. exit
  37. fi
  38. # Restart system
  39. service $WEB_BACKEND restart >/dev/null 2>&1
  40. if [ $? -ne 0 ]; then
  41. send_email_report
  42. check_result $E_RESTART "$WEB_BACKEND restart failed"
  43. fi
  44. # Update restart queue
  45. if [ -e "$VESTA/data/queue/restart.pipe" ]; then
  46. sed -i "/$SCRIPT/d" $VESTA/data/queue/restart.pipe
  47. fi
  48. #----------------------------------------------------------#
  49. # Vesta #
  50. #----------------------------------------------------------#
  51. exit