v-restart-dns 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. # Exit
  32. if [ "$1" = "no" ]; then
  33. exit
  34. fi
  35. # Schedule restart
  36. if [ "$1" = 'scheduled' ]; then
  37. echo "$BIN/$SCRIPT now" >> $VESTA/data/queue/restart.pipe
  38. exit
  39. fi
  40. if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
  41. echo "$BIN/$SCRIPT now" >> $VESTA/data/queue/restart.pipe
  42. exit
  43. fi
  44. if [ -z "$DNS_SYSTEM" ] || [ "$DNS_SYSTEM" = 'remote' ] ; then
  45. exit
  46. fi
  47. # Restart system
  48. service $DNS_SYSTEM reload >/dev/null 2>&1
  49. if [ $? -ne 0 ]; then
  50. service $DNS_SYSTEM restart >/dev/null 2>&1
  51. if [ $? -ne 0 ]; then
  52. send_email_report
  53. check_result $E_RESTART "$DNS_SYSTEM restart failed"
  54. fi
  55. fi
  56. # Update restart queue
  57. if [ -e "$VESTA/data/queue/restart.pipe" ]; then
  58. sed -i "/$SCRIPT/d" $VESTA/data/queue/restart.pipe
  59. fi
  60. #----------------------------------------------------------#
  61. # Vesta #
  62. #----------------------------------------------------------#
  63. exit