add an explicit _is_managed_service to iscsi eventscript
[sahlberg/ctdb.git] / config / events.d / 70.iscsi
1 #!/bin/sh
2 # ctdb event script for TGTD based iSCSI
3
4 . $CTDB_BASE/functions
5
6 service_name="iscsi"
7
8 ctdb_start_stop_service
9
10 is_ctdb_managed_service || exit 0
11
12 [ -z "$CTDB_START_ISCSI_SCRIPTS" ] && {
13         echo "No iscsi start script directory found"
14         exit 0
15 }
16
17 case "$1" in 
18     recovered)
19         # block the iscsi port
20         iptables -I INPUT 1 -p tcp --dport 3260 -j DROP
21         
22         # shut down the iscsi service
23         killall -9 tgtd >/dev/null 2>/dev/null
24
25         THIS_NODE=`ctdb status | grep "THIS NODE" | sed -e "s/pnn://" -e "s/ .*//"`
26         [ -z $THIS_NODE ] && {
27                 echo "70.iscsi: Failed to get node pnn"
28                 exit 0
29         }
30
31         # start the iscsi daemon
32         tgtd >/dev/null 2>/dev/null
33
34         for NODE in `ctdb ip | grep -v "Public" | egrep " ${THIS_NODE}$" | sed -e "s/ .*//"`; do
35                 [ -f $CTDB_START_ISCSI_SCRIPTS/${NODE}.sh ] && {
36                         echo Starting iscsi service for public address $NODE
37                         $CTDB_START_ISCSI_SCRIPTS/${NODE}.sh
38                 }
39         done
40
41         # remove all iptables rules
42         while iptables -D INPUT -p tcp --dport 3260 -j DROP 2>/dev/null >/dev/null ;  do
43             :
44         done
45
46         ;;
47
48     shutdown)
49         # shutdown iscsi when ctdb goes down
50         killall -9 tgtd >/dev/null 2>/dev/null
51         ;;
52
53     monitor)
54         ctdb_check_tcp_ports 3260 || exit $?
55         ;;
56
57     *)
58         ctdb_standard_event_handler "$@"
59         ;;
60 esac
61
62 exit 0