/ctdb/events.d/20.multipathd

http://github.com/brinkman83/bashrc · Shell · 99 lines · 69 code · 15 blank · 15 comment · 9 complexity · 8677e951ad07760d8c78e17233596c6a MD5 · raw file

  1. #!/bin/sh
  2. # ctdb event script for monitoring the multipath daemon
  3. #
  4. # Configure monitporing of multipath devices by listing the device serials
  5. # in /etc/ctdb/multipathd :
  6. # CTDB_MONITOR_MPDEVICES="device1 device2 ..."
  7. #
  8. . $CTDB_BASE/functions
  9. service_name="multipathd"
  10. loadconfig
  11. [ -z "$CTDB_MONITOR_MPDEVICES" ] && {
  12. exit 0
  13. }
  14. MPFAILURE=$CTDB_BASE/state/multipathd/failure
  15. multipathd_check_background()
  16. {
  17. for DEVICE in $CTDB_MONITOR_MPDEVICES; do
  18. # check that we can see all devices
  19. if [ -z "`multipath -ll $DEVICE`" ]; then
  20. echo Device $DEVICE not known to multipathd
  21. exit 1
  22. fi
  23. # check that all devices are active
  24. if [ -z "`multipath -ll $DEVICE|grep prio|grep active`" ]; then
  25. echo Device $DEVICE has no active paths
  26. exit 1
  27. fi
  28. done
  29. exit 0
  30. }
  31. multipathd_check()
  32. {
  33. # run the actual check in the background since the call to
  34. # multipath may block.
  35. (
  36. multipathd_check_background &
  37. pid="$!"
  38. timeleft=10
  39. while [ $timeleft -gt 0 ]; do
  40. timeleft=$(($timeleft - 1))
  41. # see if the process still exists
  42. /bin/kill -0 $pid > /dev/null 2>&1 || {
  43. # it doesn't exist, grab its exit status
  44. wait $pid
  45. [ $? = 0 ] || {
  46. echo "20.multipathd: multipath background update exited with status $?"
  47. touch $MPFAILURE
  48. exit 1
  49. }
  50. rm $MPFAILURE 2>/dev/null
  51. exit 0
  52. }
  53. sleep 1
  54. done
  55. echo "20.multipathd: Callout to multipath checks hung."
  56. touch $MPFAILURE
  57. exit 1
  58. ) &
  59. if [ -f $MPFAILURE ]; then
  60. return 1
  61. else
  62. return 0
  63. fi
  64. }
  65. case "$1" in
  66. startup)
  67. # create a state directory to keep/track the multipath device
  68. # state
  69. /bin/mkdir -p $CTDB_BASE/state/multipathd
  70. exit 0
  71. ;;
  72. monitor)
  73. multipathd_check
  74. [ "$?" = "0" ] || {
  75. echo 20.multipathd: monitoring of multipathing failed
  76. exit 1
  77. }
  78. exit 0
  79. ;;
  80. *)
  81. ctdb_standard_event_handler "$@"
  82. ;;
  83. esac
  84. exit 0