eventscripts: Rework the iSCSI eventscript
[Samba/wip.git] / ctdb / config / events.d / 70.iscsi
blobcedaf40434edabc4a3507dccc3164671d118ec3e
1 #!/bin/sh
2 # ctdb event script for TGTD based iSCSI
4 [ -n "$CTDB_BASE" ] || \
5 export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")
7 . $CTDB_BASE/functions
9 service_name="iscsi"
11 loadconfig
13 ctdb_start_stop_service
15 is_ctdb_managed_service || exit 0
17 [ -z "$CTDB_START_ISCSI_SCRIPTS" ] && {
18 echo "No iscsi start script directory found"
19 exit 0
22 case "$1" in
23 ipreallocated)
24 # block the iscsi port
25 iptables -I INPUT 1 -p tcp --dport 3260 -j DROP
27 # shut down the iscsi service
28 killall -9 tgtd >/dev/null 2>/dev/null
30 this_node=$(ctdb xpnn | sed -e 's@PNN:@@')
31 if [ -z "$this_node" ] ; then
32 echo "Failed to get node pnn"
33 exit 0
36 # start the iscsi daemon
37 tgtd >/dev/null 2>/dev/null
39 ips=$(ctdb -Y ip | awk -F: -v pnn=$this_node '$3 == pnn {print $2}')
40 for ip in $ips ; do
41 script="${CTDB_START_ISCSI_SCRIPTS}/${ip}.sh"
42 if [ -x "$script" ] ; then
43 echo "Starting iscsi service for public address ${ip}"
44 "$script"
46 done
48 # remove all iptables rules
49 while iptables -D INPUT -p tcp --dport 3260 -j DROP >/dev/null 2>&1 ; do
51 done
55 shutdown)
56 # shutdown iscsi when ctdb goes down
57 killall -9 tgtd >/dev/null 2>/dev/null
60 monitor)
61 ctdb_check_tcp_ports 3260 || exit $?
65 ctdb_standard_event_handler "$@"
67 esac
69 exit 0