make changes to ctdb event scripts to support NFS-Ganesha.
[sahlberg/ctdb.git] / config / events.d / 60.ganesha
1 #!/bin/sh
2 # script to manage nfs in a clustered environment
3
4 start_nfs() {
5        /bin/mkdir -p $CTDB_VARDIR/state/nfs
6        /bin/mkdir -p $CTDB_VARDIR/state/statd/ip
7        ctdb_service_stop
8        ctdb_service_start
9        echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
10 }
11
12 . $CTDB_BASE/functions
13
14 loadconfig nfs
15
16 [ "$NFS_SERVER_MODE" == "GANESHA" ] || exit 0
17
18 service_name="nfs-ganesha-gpfs"
19
20 ctdb_start_stop_service
21
22 is_ctdb_managed_service || exit 0
23
24 case "$1" in
25      init)
26        # read statd from persistent database
27        ;;
28      startup)
29        ctdb_service_start
30        mkdir -p $CTDB_VARDIR/state/statd
31        touch $CTDB_VARDIR/state/statd/update-trigger
32        ;;
33
34      shutdown)
35        ctdb_service_stop
36        ;;
37
38      takeip)
39        ctdb_service_set_reconfigure
40        ;;
41
42      releaseip)
43        ctdb_service_set_reconfigure
44        ;;
45
46       monitor)
47        if ctdb_service_needs_reconfigure ; then
48            ctdb_service_reconfigure
49            exit 0
50        fi
51
52        update_tickles 2049
53
54        # check that statd responds to rpc requests
55        # if statd is not running we try to restart it
56        if ctdb_check_rpc "STATD" status 1 >/dev/null ; then
57                (service_name="nfs_statd"; ctdb_counter_init)
58        else
59                p="rpc.statd" ; cmd="$p"
60                cmd="${cmd}${STATD_HOSTNAME:+ -n }${STATD_HOSTNAME}"
61                cmd="${cmd}${STATD_PORT:+ -p }${STATD_PORT}"
62                cmd="${cmd}${STATD_OUTGOING_PORT:+ -o }${STATD_OUTGOING_PORT}"
63                (
64                        service_name="nfs_statd"
65                        ctdb_counter_incr
66                        ctdb_check_counter_limit 10 quiet >/dev/null
67                ) || {
68                        echo "$ctdb_check_rpc_out"
69                        echo "Trying to restart STATD [$cmd]"
70                }
71                $cmd
72        fi
73
74        # check that NFS responds to rpc requests
75        [ "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" = "yes" ] || {
76            if ctdb_check_rpc "NFS" nfs 3 >/dev/null ; then
77                (service_name="nfs_knfsd"; ctdb_counter_init)
78            else
79                (
80                        service_name="nfs_knfsd"
81                        ctdb_counter_incr
82
83                        ctdb_check_counter_equal 10 || {
84                                echo "Trying to restart NFS service"
85                                ctdb_service_stop
86                                ctdb_service_start
87                                exit 0
88                        }
89
90                        ctdb_check_counter_limit 15 quiet >/dev/null
91                ) || {
92                        echo "$ctdb_check_rpc_out"
93                        echo "Trying to restart NFS service"
94                        ctdb_service_stop
95                        ctdb_service_start
96                        exit 1
97                }
98            fi
99        }
100
101        # and that its directories are available
102        [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
103            grep Path /etc/ganesha/gpfs.ganesha.exports.conf |
104            cut -f2 -d\" | ctdb_check_directories
105        } || exit $?
106
107        # check that lockd responds to rpc requests
108        ctdb_check_rpc "LOCKD" nlockmgr 4 || {
109                echo "Trying to restart lock manager service"
110                ctdb_service_stop
111                ctdb_service_start
112                exit 1
113        }
114
115        # check mounts responds to rpc requests
116        ctdb_check_rpc "MOUNTD" mountd 1 >/dev/null || {
117                echo "Trying to restart mountd service"
118                ctdb_service_stop
119                ctdb_service_start
120                exit 1
121        }
122
123        # rquotad needs special handling since it is sometimes not started
124        # correctly on RHEL5
125        # this is not a critical service so we dont flag the node as unhealthy
126        ctdb_check_rpc "RQUOTAD" rquotad 1 || {
127                p="rpc.rquotad"
128                cmd="${p}${RQUOTAD_PORT:+ -p }${RQUOTAD_PORT}"
129                echo "Trying to restart RQUOTAD [${cmd}]"
130                killall -q -9 $p
131                $cmd &
132        }
133
134        # once every 60 seconds, update the statd state database for which
135        # clients need notifications
136        LAST_UPDATE=`stat --printf="%Y" $CTDB_VARDIR/state/statd/update-trigger 2>/dev/null`
137        CURRENT_TIME=`date +"%s"`
138        [ $CURRENT_TIME -ge $(($LAST_UPDATE + 60)) ] && {
139            mkdir -p $CTDB_VARDIR/state/statd
140            touch $CTDB_VARDIR/state/statd/update-trigger
141            $CTDB_BASE/statd-callout updatelocal &
142            $CTDB_BASE/statd-callout updateremote &
143        }
144                ;;
145
146     ipreallocated)
147        # if the ips have been reallocated, we must restart the lockmanager
148        # across all nodes and ping all statd listeners
149        [ -x $CTDB_BASE/statd-callout ] && {
150                $CTDB_BASE/statd-callout notify &
151        } >/dev/null 2>&1
152        ;;
153     *)
154        ctdb_standard_event_handler "$@"
155        ;;
156 esac
157
158 exit 0