v-restart-cron 1.9 KB

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