Whamcloud - gitweb
b=9729
[fs/lustre-release.git] / lustre / scripts / lustre
1 #!/bin/sh
2 #
3 # lustre   This shell script takes care of starting and stopping Lustre
4 #
5 # chkconfig: 345 99 1
6 # description: Lustre Lite network File System.                              \
7 #              This starts both Lustre client and server functions.
8 # processname: lconf
9 # config: /etc/lustre/config.xml
10 # pidfile: /var/run/lustre.pid
11
12 SERVICE=lustre
13 LOCK=/var/lock/subsys/$SERVICE
14
15 : ${LUSTRE_CFG:=/etc/lustre/lustre.cfg}
16 [ -f ${LUSTRE_CFG} ] && . ${LUSTRE_CFG}
17
18 : ${LUSTRE_CONFIG_XML:=/etc/lustre/config.xml}
19 : ${LCONF:=/usr/sbin/lconf}
20 : ${LCONF_START_ARGS:="${LUSTRE_CONFIG_XML}"}
21 : ${LCONF_STOP_ARGS:="--force --cleanup ${LUSTRE_CONFIG_XML}"}
22 : ${LCTL:=/usr/sbin/lctl}
23
24 # Source function library.
25 if [ -f /etc/init.d/functions ] ; then
26    . /etc/init.d/functions
27 fi
28
29 # Source networking configuration.
30 if [ -f /etc/sysconfig/network ] ; then
31    . /etc/sysconfig/network
32 fi
33
34 # Check that networking is up.
35 [ "${NETWORKING}" = "no" ] && exit 0
36
37 [ -x ${LCONF} -a -x ${LCTL} ] || exit 0
38
39 [ -f ${LUSTRE_CONFIG_XML} ] || ( echo "unconfigured" && exit 0 )
40
41 # Create /var/lustre directory 
42 # This is used by snmp agent for checking lustre services        \
43 #    status online/offline/online pending/offline pending.
44
45 [ -d ${STATUS_DIR:=/var/lustre} ] || mkdir -p $STATUS_DIR
46 STATUS=${STATUS_DIR}/sysStatus
47
48 start() {
49         echo -n "Starting $SERVICE: "
50         ${LCONF} ${LCONF_START_ARGS}
51         RETVAL=$?
52         echo $SERVICE
53         if [ $RETVAL -eq 0 ]; then
54                touch $LOCK
55               echo "online" >$STATUS
56         else
57               echo "online pending" >$STATUS
58         fi
59 }
60
61 stop() {
62         echo -n "Shutting down $SERVICE: "
63         ${LCONF} ${LCONF_STOP_ARGS}
64         RETVAL=$?
65         echo $SERVICE
66         rm -f $LOCK 
67         if [ $RETVAL -eq 0 ]; then
68               echo "offline" >$STATUS
69         else
70               echo "offline pending" >$STATUS
71         fi
72 }
73
74 restart() {
75         stop
76         start
77 }
78
79 status() {
80         ${LCTL} dl 2>/dev/null | while read INDEX STAT MODULE NAME; do
81                 case $MODULE in
82                         ost|mds|osc|mdc)
83                                 [ "`grep -v FULL /proc/fs/lustre/*c/*/*_server_uuid`" ] \
84                                 && echo "recovery" || echo "running"
85                                 return
86                                 ;;
87                 esac
88         done
89         echo "stopped"
90 }
91
92 # See how we were called.
93 case "$1" in
94   start)
95         start
96         ;;
97   stop)
98         stop
99         ;;
100   restart)
101         restart
102         ;;
103   status)
104         status $SERVICE
105         ;;
106   *)
107         echo "Usage: $SERVICE {start|stop|restart|status}"
108         exit 1
109 esac
110
111 exit $RETVAL