v-restart-dns 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # info: restart dns service
  3. # options: NONE
  4. #
  5. # The function tells BIND service to reload dns zone files.
  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. if [ -e '/etc/named.conf' ]; then
  15. dns_conf='/etc/named.conf'
  16. else
  17. dns_conf='/etc/bind/named.conf'
  18. fi
  19. email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
  20. email=$(echo "$email" | cut -f 2 -d "'")
  21. tmpfile=$(mktemp)
  22. subj="$(hostname): $DNS_SYSTEM restart failed"
  23. /usr/sbin/named-checkconf $dns_conf >> $tmpfile 2>&1
  24. service $DNS_SYSTEM restart >> $tmpfile 2>&1
  25. cat $tmpfile |$SENDMAIL -s "$subj" $email
  26. rm -f $tmpfile
  27. }
  28. #----------------------------------------------------------#
  29. # Action #
  30. #----------------------------------------------------------#
  31. # Schedule restart
  32. if [ "$1" = 'scheduled' ]; then
  33. echo "$BIN/$SCRIPT now" >> $VESTA/data/queue/restart.pipe
  34. exit
  35. fi
  36. if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
  37. echo "$BIN/$SCRIPT now" >> $VESTA/data/queue/restart.pipe
  38. exit
  39. fi
  40. if [ -z "$DNS_SYSTEM" ] || [ "$DNS_SYSTEM" = 'remote' ] ; then
  41. exit
  42. fi
  43. # Restart system
  44. service $DNS_SYSTEM reload >/dev/null 2>&1
  45. if [ $? -ne 0 ]; then
  46. service $DNS_SYSTEM restart >/dev/null 2>&1
  47. if [ $? -ne 0 ]; then
  48. send_email_report
  49. check_result $E_RESTART "$DNS_SYSTEM restart failed"
  50. fi
  51. fi
  52. # Update restart queue
  53. if [ -e "$VESTA/data/queue/restart.pipe" ]; then
  54. sed -i "/$SCRIPT/d" $VESTA/data/queue/restart.pipe
  55. fi
  56. #----------------------------------------------------------#
  57. # Vesta #
  58. #----------------------------------------------------------#
  59. exit