Advertisement
Guest User

Raid1-HA diff

a guest
Oct 9th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.50 KB | None | 0 0
  1. --- Raid1.backup 2014-09-28 19:07:15.436006749 -0400
  2. +++ Raid1 2014-10-09 08:33:32.447596671 -0400
  3. @@ -43,7 +43,7 @@
  4.  
  5. usage() {
  6. cat <<-EOT
  7. - usage: $0 {start|stop|status|monitor|validate-all|usage|meta-data}
  8. + usage: $0 {start|stop|status|monitor|promote|demote|notify|validate-all|usage|meta-data}
  9. EOT
  10. }
  11.  
  12. @@ -132,6 +132,26 @@
  13. <content type="boolean" default="false" />
  14. </parameter>
  15.  
  16. +
  17. +<parameter name="master_slave_mode" unique="0" required="0">
  18. +<longdesc lang="en">
  19. +Allows for ms style configuration which activates the resource on both nodes
  20. +with master being readwrite and slave being readonly.
  21. +</longdesc>
  22. +<shortdesc lang="en">allows for ms style configurations.</shortdesc>
  23. +<content type="boolean" default="false" />
  24. +</parameter>
  25. +
  26. +
  27. +<parameter name="preferred_master" unique="0" required="0">
  28. +<longdesc lang="en">
  29. +Allows for ms style configuration which activates the resource on both nodes
  30. +with master being readwrite and slave being readonly.
  31. +</longdesc>
  32. +<shortdesc lang="en">allows for ms style configurations.</shortdesc>
  33. +<content type="string" default="" />
  34. +</parameter>
  35. +
  36. </parameters>
  37.  
  38. <actions>
  39. @@ -141,11 +161,198 @@
  40. <action name="monitor" depth="0" timeout="20s" interval="10" />
  41. <action name="validate-all" timeout="5" />
  42. <action name="meta-data" timeout="5" />
  43. +<action name="promote" timeout="20" />
  44. +<action name="demote" timeout="20" />
  45. +<action name="notify" timeout="20" />
  46. +
  47. </actions>
  48. </resource-agent>
  49. END
  50. }
  51.  
  52. +raid1_notify() {
  53. + local type_op="${OCF_RESKEY_CRM_meta_notify_type}-${OCF_RESKEY_CRM_meta_notify_operation}"
  54. + local md=`echo $MDDEV | sed 's,/dev/,,'`
  55. + ocf_log info "Received '$type_op' notification."
  56. + case "$type_op" in
  57. + 'post-promote')
  58. + ocf_log info "Received '$type_op' notification for node(s): $OCF_RESKEY_CRM_meta_notify_promote_uname"
  59. + # If the notification is not for this node, then update the remote target group state
  60. + for i in $OCF_RESKEY_CRM_meta_notify_promote_uname; do
  61. + master_host="$i"
  62. + if [ `uname -n` = $master_host ]; then
  63. + if [ `cat /sys/block/$md/md/array_state` = readonly ]; then
  64. + ocf_run $MDADM --misc --readwrite $MDDEV || exit $OCF_ERR_GENERIC
  65. + fi
  66. + ocf_log info "Ignoring my own promotion. Nothing to do"
  67. + return $OCF_SUCCESS
  68. + fi
  69. + if [ `cat /sys/block/$md/md/array_state` != readonly ]; then
  70. + ocf_run $MDADM --misc -o $MDDEV || exit $OCF_ERR_GENERIC
  71. + else
  72. + return $OCF_SUCCESS
  73. + fi
  74. + done
  75. + ;;
  76. + 'post-demote')
  77. + ocf_log info "Received '$type_op' notification for node(s): $OCF_RESKEY_CRM_meta_notify_demote_uname"
  78. + # If the notification is not for this node, then update the remote target group state
  79. + for i in $OCF_RESKEY_CRM_meta_notify_demote_uname; do
  80. + master_host="$i"
  81. + if [ `uname -n` = $master_host ]; then
  82. + if [ `cat /sys/block/$md/md/array_state` != readonly ]; then
  83. + ocf_run $MDADM --misc -o $MDDEV || exit $OCF_ERR_GENERIC
  84. + fi
  85. + ocf_log info "Ignoring my own promotion. Nothing to do"
  86. + return $OCF_SUCCESS
  87. + fi
  88. + if [ `cat /sys/block/$md/md/array_state` = readonly ]; then
  89. + ocf_run $MDADM --misc --readwrite $MDDEV || exit $OCF_ERR_GENERIC
  90. + else
  91. + ocf_log info "Ignoring $master_host being demoted Nothing to do"
  92. + return $OCF_SUCCESS
  93. + fi
  94. + done
  95. + ;;
  96. + esac
  97. + return $OCF_SUCCESS
  98. +}
  99. +
  100. +
  101. +raid1_promote() {
  102. + raid1_status
  103. + local rc=${?}
  104. + case "${rc}" in
  105. + "${OCF_SUCCESS}")
  106. + # Running as Slave; normal, expected behavior
  107. + ocf_log info "raid1_promote() -> Resource is" \
  108. + "currently running as Slave."
  109. + ;;
  110. + "${OCF_RUNNING_MASTER}")
  111. + # Already running as Master; nothing to do
  112. + ocf_log info "raid1_promote() -> Resource is" \
  113. + "currently running as Master"
  114. + return ${OCF_SUCCESS}
  115. + ;;
  116. + "${OCF_NOT_RUNNING}")
  117. + # Not running; getting a demote action in this state is unexpected
  118. + ocf_log err "Resource is currently not running."
  119. + exit ${OCF_ERR_GENERIC}
  120. + ;;
  121. + *)
  122. + # Failed resource; let the cluster manager recover
  123. + ocf_log err "Unexpected error, cannot demote."
  124. + exit ${rc}
  125. + ;;
  126. + esac
  127. +
  128. + if ocf_is_true ${OCF_RESKEY_master_slave_mode}; then
  129. + # Set the mddev to readwrite on the slave
  130. + ocf_log info "raid1_promote() -> Setting $MDDEV to rw"
  131. + ocf_run $MDADM --misc --readwrite $MDDEV || exit ${OCF_ERR_GENERIC}
  132. + crm_master -l reboot -v 100
  133. + else
  134. + ocf_log err "Need to configure master slave mode before trying to promote/demote"
  135. + exit ${OCF_ERR_CONFIGURED}
  136. + fi
  137. +
  138. + # After the resource has been demoted, check whether the demotion worked
  139. + while true; do
  140. + raid1_status
  141. + if [ ${?} -ne ${OCF_RUNNING_MASTER} ]; then
  142. + ocf_log info "raid1_promote() -> Resource still" \
  143. + "awaiting promotion."
  144. + sleep 5
  145. + else
  146. + ocf_log info "Resource was promoted successfully."
  147. + break
  148. + fi
  149. + done
  150. +
  151. + # Only return $OCF_SUCCESS if _everything_ succeeded as expected
  152. + return ${OCF_SUCCESS}
  153. +}
  154. +
  155. +
  156. +raid1_demote() {
  157. + raid1_status
  158. + local rc=${?}
  159. + case "${rc}" in
  160. + "${OCF_RUNNING_MASTER}")
  161. + # Running as Master; normal, expected behavior
  162. + ocf_log info "raid1_demote() -> Resource is" \
  163. + "currently running as Master."
  164. + ;;
  165. + "${OCF_SUCCESS}")
  166. + # Already running as Slave; nothing to do
  167. + ocf_log info "raid1_demote() -> Resource is" \
  168. + "currently running as Slave."
  169. + return ${OCF_SUCCESS}
  170. + ;;
  171. + "${OCF_NOT_RUNNING}")
  172. + # Not running; getting a demote action in this state is unexpected
  173. + ocf_log err "Resource is currently not running."
  174. + exit ${OCF_ERR_GENERIC}
  175. + ;;
  176. + *)
  177. + # Failed resource; let the cluster manager recover
  178. + ocf_log err "Unexpected error, cannot demote."
  179. + exit ${rc}
  180. + ;;
  181. + esac
  182. +
  183. + if ocf_is_true ${OCF_RESKEY_master_slave_mode}; then
  184. + if [ ! `$MDADM --detail $MDDEV | grep -e '(Check Status*|Resync Status*)'` ]; then
  185. + # Set the mddev to readonly on the slave
  186. + ocf_log info "raid1_demote() -> Setting $MDDEV to ro"
  187. + ocf_run $MDADM --misc -o $MDDEV || exit ${OCF_ERR_GENERIC}
  188. + crm_master -l reboot -D
  189. + else
  190. + ocf_log err "Will not demote while operation is in progress on $MDDEV"
  191. + exit ${OCF_ERR_GENERIC}
  192. + fi
  193. + else
  194. + ocf_log err "Need to configure master slave mode before trying to demote"
  195. + exit ${OCF_ERR_CONFIGURED}
  196. + fi
  197. +
  198. + # After the resource has been demoted, check whether the demotion worked
  199. + while true; do
  200. + raid1_status
  201. + if [ ${?} -eq ${OCF_RUNNING_MASTER} ]; then
  202. + ocf_log info "raid1_demote() -> Resource still" \
  203. + "awaiting demotion."
  204. + sleep 5
  205. + else
  206. + ocf_log info "Resource was demoted successfully."
  207. + break
  208. + fi
  209. + done
  210. +
  211. + # Only return $OCF_SUCCESS if _everything_ succeeded as expected
  212. + return ${OCF_SUCCESS}
  213. +}
  214. +
  215. +check_mdadm_version() {
  216. + if [ "$OCF_RESKEY_master_slave_mode" != "false" ]; then
  217. + local v=`$MDADM --version 2>&1 | cut -d"-" -f2 | cut -d"v" -f2`
  218. + if [[ `echo $v` =~ 3.3.[0-9] || `echo $v` =~ 3.3 ]]; then
  219. + ocf_log info "mdadm `echo $v` found and ms mode is enabled!"
  220. + else
  221. + ocf_log err "mdadm version => 3.3 required"
  222. + return ${OCF_ERR_GENERIC}
  223. + fi
  224. + fi
  225. + return $OCF_SUCCESS
  226. +}
  227. +
  228. +get_raid1_state() {
  229. + local mddev=$1
  230. + local md=`echo $mddev | sed 's,/dev/,,'`
  231. + local outp
  232. + outp=`cat /sys/block/$md/md/array_state`
  233. + echo "$outp"
  234. +}
  235. udev_settle() {
  236. if ocf_is_true $WAIT_FOR_UDEV; then
  237. udevadm settle $*
  238. @@ -181,15 +388,26 @@
  239. }
  240.  
  241. md_assemble() {
  242. - local mddev=$1
  243. - $MDADM --assemble $mddev --config=$RAIDCONF $MDADM_HOMEHOST
  244. - udev_settle --exit-if-exists=$mddev
  245. + local mddev=$1
  246. + if [ "$OCF_RESKEY_master_slave_mode" = "true" ]; then
  247. + $MDADM --assemble $mddev --readonly --config=$RAIDCONF $MDADM_HOMEHOST
  248. + else
  249. + $MDADM --assemble $mddev --config=$RAIDCONF $MDADM_HOMEHOST
  250. + fi
  251. + udev_settle --exit-if-exists=$mddev
  252. +
  253. }
  254. #
  255. # START: Start up the RAID device
  256. #
  257. raid1_start() {
  258. local rc
  259. + check_mdadm_version
  260. + rc=$?
  261. + if [ $rc -ne $OCF_SUCCESS ]; then
  262. + ocf_log err "Didn't pass the version check. Make sure you have the latest mdadm installed!"
  263. + return $OCF_ERR_GENERIC
  264. + fi
  265. raid1_monitor
  266. rc=$?
  267. if [ $rc -eq $OCF_SUCCESS ]; then
  268. @@ -268,7 +486,7 @@
  269. get_users_pids() {
  270. local mddev=$1
  271. local outp l
  272. - ocf_log debug "running lsof to list $mddev users..."
  273. + ocf_log info "running lsof to list $mddev users..."
  274. outp=`lsof $mddev | tail -n +2`
  275. echo "$outp" | awk '{print $2}' | sort -u
  276. echo "$outp" | while read l; do
  277. @@ -406,7 +624,9 @@
  278. ocf_log err "$mddev: I/O error on read"
  279. return $OCF_ERR_GENERIC
  280. fi
  281. -
  282. + if [ "$OCF_RESKEY_master_slave_mode" = "true" -a `get_raid1_state $MDDEV` != readonly ]; then
  283. + return $OCF_RUNNING_MASTER
  284. + fi
  285. return $OCF_SUCCESS
  286. }
  287.  
  288. @@ -460,6 +680,7 @@
  289. MDDEV="$OCF_RESKEY_raiddev"
  290. FORCESTOP="${OCF_RESKEY_force_stop:-1}"
  291. WAIT_FOR_UDEV="${OCF_RESKEY_udev:-1}"
  292. +PREFERRED_MASTER="$OCF_RESKEY_preferred_master"
  293.  
  294. if [ -z "$RAIDCONF" ] ; then
  295. ocf_log err "Please set OCF_RESKEY_raidconf!"
  296. @@ -544,6 +765,15 @@
  297. monitor)
  298. raid1_monitor
  299. ;;
  300. + promote)
  301. + raid1_promote
  302. + ;;
  303. + demote)
  304. + raid1_demote
  305. + ;;
  306. + notify)
  307. + raid1_notify
  308. + ;;
  309. validate-all)
  310. raid1_validate_all
  311. ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement