ctdb-scripts: Add default filesystem usage warnings
[Samba.git] / ctdb / config / events.d / 70.iscsi
blob33b71c42ada97e0da27ab64dc3338af7f5ef419f
1 #!/bin/sh
3 # CTDB event script for TGTD based iSCSI
5 [ -n "$CTDB_BASE" ] || \
6 export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")
8 . $CTDB_BASE/functions
10 service_name="iscsi"
12 loadconfig
14 ctdb_start_stop_service
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 while IFS='|' read x ip pnn x ; do
33 case "$ip" in
34 *:*) have_ipv6=true ;;
35 *) have_ipv4=true ;;
36 esac
37 done <<EOF
38 $all_ips
39 EOF
40 if $have_ipv4 ; then
41 iptables -I INPUT 1 -p tcp --dport 3260 -j DROP
43 if $have_ipv6 ; then
44 ip6tables -I INPUT 1 -p tcp --dport 3260 -j DROP
47 # Stop iSCSI daemon
48 killall -9 tgtd >/dev/null 2>/dev/null
50 ctdb_get_pnn
51 [ -n "$pnn" ] || die "Failed to get node pnn"
53 # Start iSCSI daemon
54 tgtd >/dev/null 2>&1
56 # Run a script for each currently hosted public IP address
57 ips=$(echo "$all_ips" | awk -F'|' -v pnn=$pnn '$3 == pnn {print $2}')
58 for ip in $ips ; do
59 script="${CTDB_START_ISCSI_SCRIPTS}/${ip}.sh"
60 if [ -x "$script" ] ; then
61 echo "Starting iSCSI service for public address ${ip}"
62 "$script"
64 done
66 # Unblock iSCSI port. These can be unconditional (compared to
67 # blocking above), since errors are redirected.
68 while iptables -D INPUT -p tcp --dport 3260 -j DROP >/dev/null 2>&1 ; do
70 done
71 while ip6tables -D INPUT -p tcp --dport 3260 -j DROP >/dev/null 2>&1 ; do
73 done
77 shutdown)
78 # Shutdown iSCSI daemon when ctdb goes down
79 killall -9 tgtd >/dev/null 2>&1
82 monitor)
83 ctdb_check_tcp_ports 3260 || exit $?
87 ctdb_standard_event_handler "$@"
89 esac
91 exit 0