+status() {
+ STATE="stopped"
+ # LSB compliance - return 3 if service is not running
+ # Lustre-specific returns
+ # 150 - partial startup
+ # 151 - health_check unhealthy
+ # 152 - LBUG
+ RETVAL=3
+ egrep -q "libcfs|lvfs|portals" /proc/modules && STATE="loaded"
+
+ # check for any routes - on a portals router this is the only thing
+ [ "`cat /proc/sys/lnet/routes 2> /dev/null`" ] && STATE="running" && RETVAL=0
+
+ # check for any configured devices (may indicate partial startup)
+ if [ -d /proc/fs/lustre ]; then
+ [ "`cat /proc/fs/lustre/devices 2> /dev/null`" ] && STATE="partial" && RETVAL=150
+
+ # check for either a server or a client filesystem
+ MDS="`ls /proc/fs/lustre/mds/*/recovery_status 2> /dev/null`"
+ OST="`ls /proc/fs/lustre/obdfilter/*/recovery_status 2> /dev/null`"
+ LLITE="`ls /proc/fs/lustre/llite/fs* 2> /dev/null`"
+ [ "$MDS" -o "$OST" -o "$LLITE" ] && STATE="running" && RETVAL=0
+ else
+ # check if this is a router
+ if [ -d /proc/sys/lnet ]; then
+ ROUTER="`cat /proc/sys/lnet/routes | head -1 | grep -i -c \"Routing enabled\"`"
+ if [[ ! -z ${ROUTER} && ${ROUTER} -ge 1 ]]; then
+ STATE="running"
+ RETVAL=0
+ fi
+ fi
+ fi
+
+ # check for server disconnections
+ DISCON="`grep -v FULL /proc/fs/lustre/*c/*/*server_uuid 2> /dev/null`"
+ [ "$DISCON" ] && STATE="disconnected" && RETVAL=0
+
+ # check for servers in recovery
+ [ "$MDS$OST" ] && grep -q RECOV $MDS $OST && STATE="recovery" && RETVAL=0
+
+ # check for error in health_check
+ HEALTH="/proc/fs/lustre/health_check"
+ [ -f "$HEALTH" ] && grep -q "NOT HEALTHY" $HEALTH && STATE="unhealthy" && RETVAL=151
+
+ # check for LBUG
+ [ -f "$HEALTH" ] && grep -q "LBUG" $HEALTH && STATE="LBUG" && RETVAL=152
+
+ # If Lustre is up , check if the service really exists
+ # Skip this is we are not checking a specific service
+ if [ $RETVAL -eq 0 ] && [ $SERVICE != 'lustre' ]; then
+ DUMMY=`lctl dl | grep $SERVICE`
+ [ $? -ne 0 ] && STATE="not_found" && RETVAL=3
+ fi
+
+ echo $STATE
+}
+