s3-rpc_server: Log authorization to DCE/RPC for anonymous and ncacn_np pass-though
[Samba.git] / ctdb / config / events.d / 70.iscsi
blob8851c594467f18432b4eda3b4a7e5a5f2b13e20f
1 #!/bin/sh
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
12 service_name="iscsi"
14 loadconfig
16 is_ctdb_managed_service || exit 0
18 [ -z "$CTDB_START_ISCSI_SCRIPTS" ] && {
19 echo "No iscsi start script directory found"
20 exit 0
23 case "$1" in
24 ipreallocated)
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.
30 have_ipv4=false
31 have_ipv6=false
32 # x is intentionally ignored
33 # shellcheck disable=SC2034
34 while IFS='|' read x ip pnn x ; do
35 case "$ip" in
36 *:*) have_ipv6=true ;;
37 *) have_ipv4=true ;;
38 esac
39 done <<EOF
40 $all_ips
41 EOF
42 if $have_ipv4 ; then
43 iptables -I INPUT 1 -p tcp --dport 3260 -j DROP
45 if $have_ipv6 ; then
46 ip6tables -I INPUT 1 -p tcp --dport 3260 -j DROP
49 # Stop iSCSI daemon
50 killall -9 tgtd >/dev/null 2>/dev/null
52 pnn=$(ctdb_get_pnn)
53 [ -n "$pnn" ] || die "Failed to get node pnn"
55 # Start iSCSI daemon
56 tgtd >/dev/null 2>&1
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}')
60 for ip in $ips ; do
61 script="${CTDB_START_ISCSI_SCRIPTS}/${ip}.sh"
62 if [ -x "$script" ] ; then
63 echo "Starting iSCSI service for public address ${ip}"
64 "$script"
66 done
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
72 done
73 while ip6tables -D INPUT -p tcp --dport 3260 -j DROP >/dev/null 2>&1 ; do
75 done
79 shutdown)
80 # Shutdown iSCSI daemon when ctdb goes down
81 killall -9 tgtd >/dev/null 2>&1
84 monitor)
85 ctdb_check_tcp_ports 3260 || exit $?
87 esac
89 exit 0