| 1 |
#!/bin/bash |
| 2 |
# Author: Lars Marowsky-Bree |
| 3 |
# |
| 4 |
# Copyright 2008 Lars Marowsky-Bree |
| 5 |
# License: GNU General Public License (GPL) |
| 6 |
|
| 7 |
# This is not an external/stonith plugin by itself, but instead a helper |
| 8 |
# script which gets installed in Dom0. |
| 9 |
|
| 10 |
# TODO: |
| 11 |
# - Error handling |
| 12 |
# - How to handle if the DomU resource doesn't exist? |
| 13 |
# - Does this truly work with split-brain? |
| 14 |
# - Is the handling of non-existent resources adequate? |
| 15 |
# ... |
| 16 |
# Basically: more testing. This is proof-of-concept and works, but deserves |
| 17 |
# validation. |
| 18 |
|
| 19 |
CMD="$1" |
| 20 |
DOMU="$2" |
| 21 |
TIMEOUT="$3" |
| 22 |
|
| 23 |
# Make sure the timeout is an integer: |
| 24 |
if [ "0$TIMEOUT" -eq 0 ]; then |
| 25 |
TIMEOUT=300 |
| 26 |
fi |
| 27 |
|
| 28 |
SetTargetRole() { |
| 29 |
local new_role="$1" |
| 30 |
crm_resource -r $DOMU --meta -p target_role -v $new_role |
| 31 |
|
| 32 |
local timeout="$TIMEOUT" |
| 33 |
|
| 34 |
# We only need to wait for "stopped". |
| 35 |
if [ "$new_role" != "stopped" ]; then |
| 36 |
return 0 |
| 37 |
fi |
| 38 |
|
| 39 |
while [ $timeout -gt 0 ]; do |
| 40 |
local rc |
| 41 |
crm_resource -W -r $DOMU 2>&1 | grep -q "is NOT running" |
| 42 |
rc=$? |
| 43 |
if [ $rc -eq 0 ]; then |
| 44 |
return 0 |
| 45 |
fi |
| 46 |
timeout=$[timeout-1]; |
| 47 |
sleep 1 |
| 48 |
done |
| 49 |
return 1 |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
case $CMD in |
| 54 |
on) SetTargetRole started |
| 55 |
exit $? |
| 56 |
;; |
| 57 |
off) SetTargetRole stopped |
| 58 |
exit $? |
| 59 |
;; |
| 60 |
reset) SetTargetRole stopped || exit 1 |
| 61 |
SetTargetRole started |
| 62 |
exit $? |
| 63 |
;; |
| 64 |
status) exit 0 |
| 65 |
;; |
| 66 |
*) ha_log.sh err "Called with unknown command: $CMD" |
| 67 |
exit 1 |
| 68 |
;; |
| 69 |
esac |
| 70 |
|
| 71 |
exit 1 |
| 72 |
|