使用Launchd和email administrator禁用heartbeat

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Launchd和email administrator禁用heartbeat相关的知识,希望对你有一定的参考价值。

Obviously you need to have heartbeatd handled by Launchd
  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. WARNING="Heartbeatd has been halted - Failover process initiated"
  11. ###
  12. # End Setup mail
  13. ###
  14. HEARTD=`/bin/ps -axcu | /usr/bin/grep -i heartbeatd > /dev/null; echo $?`
  15.  
  16. if [ ! ${HEARTD} -eq 0 ];
  17. then
  18. echo "heartbeatd is not running - uh oh..."
  19. /usr/bin/logger "FAILOVER: heartbeatd is not running - uh oh..."
  20.  
  21. echo From: ${C_NAME} - ${WARNING} > /tmp/heartbeat_warning.txt | mail -s
  22. "FAILOVER PROCESS: Heartbeatd was not running" ${NOTIFY} < /tmp/heartbeat_warning.txt
  23. else
  24. launchctl unload /Library/LaunchDaemons/uk.ac.rave.heartbeatd.plist
  25. while [ $(/bin/ps -axcu | /usr/bin/grep -i heartbeatd > /dev/null; echo $?) -eq 0 ];
  26. do
  27. echo "Halting heartbeatd"
  28. /usr/bin/logger "FAILOVER: Halting heartbeatd"
  29. /bin/sleep 5
  30. done
  31.  
  32. echo "heartbeatd has been halted"
  33. /usr/bin/logger "FAILOVER: heartbeatd has been halted"
  34.  
  35. rm -f /var/run/heartbeatd.pid
  36.  
  37. echo From: ${C_NAME} - ${WARNING} > /tmp/heartbeat_warning.txt | mail -s
  38. "FAILOVER PROCESS: Heartbeat halted - failover in process" ${NOTIFY} < /tmp/heartbeat_warning.txt
  39. fi
  40. exit 0

以上是关于使用Launchd和email administrator禁用heartbeat的主要内容,如果未能解决你的问题,请参考以下文章

Mac服务管理-Launchd(转)

Mac下用Launchd实现使用rc.local执行开机启动命令

launchd 守护程序的安全密码存储

Mac使用Launchd命令行lauchctl操作服务的简单用法

当 launchd 终止进程时是不是调用 XPC 中断处理程序?

Error: undefined method `launchd_service_path‘ for xxx