3 # CTDB event script for TGTD based iSCSI
5 [ -n "$CTDB_BASE" ] || \
6 CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD")
8 . "${CTDB_BASE}/functions"
10 # service_name is used by various functions
11 # shellcheck disable=SC2034
16 [ "$CTDB_MANAGES_ISCSI" = "yes" ] || exit 0
18 [ -z "$CTDB_START_ISCSI_SCRIPTS" ] && {
19 echo "No iscsi start script directory found"
25 all_ips=$($CTDB -X ip | tail -n +2)
27 # Block the iSCSI port. Only block for the address families
28 # we have configured. This copes with, for example, ip6tables
29 # being unavailable on an IPv4-only system.
32 # x is intentionally ignored
33 # shellcheck disable=SC2034
34 while IFS='|' read x ip pnn x ; do
36 *:*) have_ipv6=true ;;
43 iptables -I INPUT 1 -p tcp --dport 3260 -j DROP
46 ip6tables -I INPUT 1 -p tcp --dport 3260 -j DROP
50 killall -9 tgtd >/dev/null 2>/dev/null
53 [ -n "$pnn" ] || die "Failed to get node pnn"
58 # Run a script for each currently hosted public IP address
59 ips=$(echo "$all_ips" | awk -F'|' -v pnn="$pnn" '$3 == pnn {print $2}')
61 script="${CTDB_START_ISCSI_SCRIPTS}/${ip}.sh"
62 if [ -x "$script" ] ; then
63 echo "Starting iSCSI service for public address ${ip}"
68 # Unblock iSCSI port. These can be unconditional (compared to
69 # blocking above), since errors are redirected.
70 while iptables -D INPUT -p tcp --dport 3260 -j DROP >/dev/null 2>&1 ; do
73 while ip6tables -D INPUT -p tcp --dport 3260 -j DROP >/dev/null 2>&1 ; do
80 # Shutdown iSCSI daemon when ctdb goes down
81 killall -9 tgtd >/dev/null 2>&1
85 ctdb_check_tcp_ports 3260 || exit $?