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