summaryrefslogtreecommitdiffstats
path: root/ctdb/config/events.d/70.iscsi
blob: cedaf40434edabc4a3507dccc3164671d118ec3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
# ctdb event script for TGTD based iSCSI

[ -n "$CTDB_BASE" ] || \
    export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")

. $CTDB_BASE/functions

service_name="iscsi"

loadconfig

ctdb_start_stop_service

is_ctdb_managed_service || exit 0

[ -z "$CTDB_START_ISCSI_SCRIPTS" ] && {
	echo "No iscsi start script directory found"
	exit 0
}

case "$1" in 
    ipreallocated)
	# block the iscsi port
	iptables -I INPUT 1 -p tcp --dport 3260 -j DROP
	
	# shut down the iscsi service
	killall -9 tgtd >/dev/null 2>/dev/null

	this_node=$(ctdb xpnn | sed -e 's@PNN:@@')
	if [ -z "$this_node" ] ; then
		echo "Failed to get node pnn"
		exit 0
	fi

	# start the iscsi daemon
	tgtd >/dev/null 2>/dev/null

	ips=$(ctdb -Y ip | awk -F: -v pnn=$this_node '$3 == pnn {print $2}')
	for ip in $ips ; do
	    script="${CTDB_START_ISCSI_SCRIPTS}/${ip}.sh"
	    if [ -x "$script" ] ; then
		echo "Starting iscsi service for public address ${ip}"
		"$script"
	    fi
	done

	# remove all iptables rules
	while iptables -D INPUT -p tcp --dport 3260 -j DROP >/dev/null 2>&1 ; do
	    :
	done

	;;

    shutdown)
	# shutdown iscsi when ctdb goes down
	killall -9 tgtd >/dev/null 2>/dev/null
	;;

    monitor)
	ctdb_check_tcp_ports 3260 || exit $?
	;;

    *)
	ctdb_standard_event_handler "$@"
	;;
esac

exit 0