Disable heartbeatd using Launchd and email administrator


/ Published in: Bash
Save to your folder(s)

Obviously you need to have heartbeatd handled by Launchd


Copy this code and paste it in your HTML
  1. #!/bin/bash
  2.  
  3. ###
  4. # Stop heartbeatd so that failoverd initiates IPFailover
  5. # leaving network interfaces intact.
  6. ###
  7. # Setup mail
  8. ###
  9. C_NAME=`/usr/sbin/scutil --get ComputerName`
  10. NOTIFY="admin@admin.com"
  11. WARNING="Heartbeatd has been halted - Failover process initiated"
  12. ###
  13. # End Setup mail
  14. ###
  15. HEARTD=`/bin/ps -axcu | /usr/bin/grep -i heartbeatd > /dev/null; echo $?`
  16.  
  17. if [ ! ${HEARTD} -eq 0 ];
  18. then
  19. echo "heartbeatd is not running - uh oh..."
  20. /usr/bin/logger "FAILOVER: heartbeatd is not running - uh oh..."
  21.  
  22. echo From: ${C_NAME} - ${WARNING} > /tmp/heartbeat_warning.txt | mail -s \
  23. "FAILOVER PROCESS: Heartbeatd was not running" ${NOTIFY} < /tmp/heartbeat_warning.txt
  24. else
  25. launchctl unload /Library/LaunchDaemons/uk.ac.rave.heartbeatd.plist
  26. while [ $(/bin/ps -axcu | /usr/bin/grep -i heartbeatd > /dev/null; echo $?) -eq 0 ];
  27. do
  28. echo "Halting heartbeatd"
  29. /usr/bin/logger "FAILOVER: Halting heartbeatd"
  30. /bin/sleep 5
  31. done
  32.  
  33. echo "heartbeatd has been halted"
  34. /usr/bin/logger "FAILOVER: heartbeatd has been halted"
  35.  
  36. rm -f /var/run/heartbeatd.pid
  37.  
  38. echo From: ${C_NAME} - ${WARNING} > /tmp/heartbeat_warning.txt | mail -s \
  39. "FAILOVER PROCESS: Heartbeat halted - failover in process" ${NOTIFY} < /tmp/heartbeat_warning.txt
  40. fi
  41. exit 0

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.