Whamcloud - gitweb
LU-13004 ptlrpc: Allow BULK_BUF_KIOV to accept a kvec
[fs/lustre-release.git] / lustre / scripts / lnet.in
1 #!/bin/bash
2 #
3 # $Id: lnet.rc bogl Exp $
4 #
5 ### BEGIN INIT INFO
6 # Provides:          lnet
7 # Required-Start:    $network openibd
8 # Required-Stop:     $network openibd
9 # Default-Start:     3
10 # Default-Stop:      0 1 2 5 6
11 # Description:       Enable Lustre Networking
12 ### END INIT INFO
13 #
14 # lnet  This shell script takes care of starting and stopping
15 #       the lnet (Lustre networking) services.
16 #
17 # chkconfig: - 59 76
18 # description:  Part of the lustre file system.
19 # probe: true
20 # config: /etc/sysconfig/lnet
21
22 # Source function library.
23 [ -f /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions
24
25 # Source networking configuration and check that networking is up.
26 [ -f /etc/sysconfig/network ] && . /etc/sysconfig/network && \
27 [ "${NETWORKING}" = "no" ] && exit 0
28
29 # Check for and source configuration file otherwise set defaults
30 [ -f /etc/sysconfig/lnet ] && . /etc/sysconfig/lnet
31
32 declare -r awkprog='BEGIN { rc = -1 }
33                        { if ( $1 == module_name ) { rc = $3; exit; } }
34                     END { print rc }'
35
36 # Usage: run_preexec_check [ start | restart | condrestart ]
37 # The single parameter will be passed to the PREEXEC_SCRIPT
38 run_preexec_check ()
39 {
40         if [ -n "$PREEXEC_CHECK" ] && ! $PREEXEC_CHECK ; then
41                 echo "Pre-exec check \"$PREEXEC_CHECK\" failed.  Aborting."
42                 exit 1
43         fi
44
45         if [ -n "$PREEXEC_SCRIPT" ] && ! "$PREEXEC_SCRIPT" "$1" ; then
46                 echo "Pre-exec script \"$PREEXEC_SCRIPT\" failed.  Aborting."
47                 exit 1
48         fi
49 }
50
51 # Usage: run_postexec_check [ start | restart | condrestart ]
52 # The single parameter will be passed to the POSTEXEC_SCRIPT
53 run_postexec_check ()
54 {
55         if [ -n "$POSTEXEC_CHECK" ] && ! $POSTEXEC_CHECK ; then
56                 echo "Post-exec check \"$POSTEXEC_CHECK\" failed.  Aborting."
57                 exit 1
58         fi
59
60         if [ -n "$POSTEXEC_SCRIPT" ] && ! "$POSTEXEC_SCRIPT" "$1" ; then
61                 echo "Post-exec script \"$POSTEXEC_SCRIPT\" failed.  Aborting."
62                 exit 1
63         fi
64 }
65
66 status ()
67 {
68         old_nullglob="`shopt -p nullglob`"
69         shopt -u nullglob
70
71         STATE="stopped"
72         # LSB compliance - return 3 if service is not running
73         # Lustre-specific returns
74         # 150 - partial startup
75         # 151 - health_check unhealthy
76         # 152 - LBUG
77         RETVAL=3
78         egrep -q "lnet" /proc/modules && STATE="loaded"
79
80         # check for any routes - on a portals router this is the only thing
81         VAR=$(lctl get_param -n routes 2>&1)
82         if [ $? = 0 ] ; then
83                 STATE="running"
84                 RETVAL=0
85         fi
86
87         # check if this is a router
88         if [[ "$(lctl get_param -n routes)" =~ "Routing enabled" ]]; then
89                 STATE="running"
90                 RETVAL=0
91         fi
92
93         # check for error in health_check
94         local health_check=$(lctl get_param -n health_check)
95         if [[ "$health_check" =~ "NOT HEALTHY" ]]; then
96                 STATE="unhealthy"
97                 RETVAL=1
98         fi
99
100         if [[ "$health_check" =~ "LBUG" ]]; then
101                 STATE="LBUG"
102                 RETVAL=152
103         fi
104
105         echo $STATE
106         eval $old_nullglob
107 }
108
109 # See how we were called.
110 case "$1" in
111   start)
112         run_preexec_check "start"
113         touch /var/lock/subsys/lnet
114         modprobe lnet || exit 1
115         lnetctl lnet configure || exit 1
116         lnetctl import < "@sysconfdir@/lnet.conf"
117         run_postexec_check "start"
118         ;;
119   stop)
120         run_preexec_check "stop"
121         lustre_rmmod ptlrpc || exit 1
122         lnetctl lnet unconfigure || exit 1
123         lustre_rmmod libcfs ldiskfs || exit 1
124         rm -f /var/lock/subsys/lnet
125         run_postexec_check "stop"
126         ;;
127   status)
128         status
129         ;;
130   restart)
131         $0 stop
132         $0 start
133         ;;
134   reload)
135         touch /var/lock/subsys/lnet
136         ;;
137   probe)
138         if [ ! -f /var/lock/subsys/lnet ] ; then
139           echo $"start"; exit 0
140         fi
141         ;;
142   condrestart)
143         [ -f /var/lock/subsys/lnet ] && {
144                 $0 stop
145                 $0 start
146         }
147         ;;
148   *)
149         echo $"Usage: lnet {start|stop|status|restart|reload|condrestart}"
150         exit 1
151 esac
152
153 exit 0