v-restart-dns 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. send_email_report() {
  13. if [ -e '/etc/named.conf' ]; then
  14. dns_conf='/etc/named.conf'
  15. else
  16. dns_conf='/etc/bind/named.conf'
  17. fi
  18. send_mail="$VESTA/web/inc/mail-wrapper.php"
  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. named-checkconf $dns_conf >> $tmpfile 2>&1
  24. /etc/init.d/$DNS_SYSTEM restart >> $tmpfile 2>&1
  25. cat $tmpfile | $send_mail -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" ]; then
  41. exit
  42. fi
  43. # Restart system
  44. /etc/init.d/$DNS_SYSTEM reload >/dev/null 2>&1
  45. if [ $? -ne 0 ]; then
  46. /etc/init.d/$DNS_SYSTEM restart >/dev/null 2>&1
  47. if [ $? -ne 0 ]; then
  48. send_email_report
  49. echo "Error: $DNS_SYSTEM restart failed"
  50. exit $E_RESTART
  51. fi
  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