#!/bin/sh
#
# lustre   This shell script starts stops and monitors a lustre OST
#
# chkconfig: 345 99 1
# description: Lustre network File System.                              \
#
# processname: lustre
# config: /etc/cluster/

SERVICE=`basename $0`
LOCK=/var/lock/subsys/$SERVICE
HOST=`hostname -s`

# Source function library.
if [ -f /etc/init.d/functions ] ; then
   . /etc/init.d/functions
fi

# Source networking configuration.
if [ -f /etc/sysconfig/network ] ; then
   . /etc/sysconfig/network
fi

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

start() {
        echo -n "Starting $SERVICE: "
        mkdir -p /mnt/lustre/${SERVICE}
        mount -v -t lustre LABEL=$SERVICE /mnt/lustre/${SERVICE}
        RETVAL=$?
}

stop() {
        echo -n "Shutting down $SERVICE: "
        umount -f /mnt/lustre/${SERVICE}
        RETVAL=$?
        rm -f $LOCK 
}

restart() {
	stop
	start
}

status() {
        # check OST is mounted
	[ -e /proc/fs/lustre/obdfilter/proc/fs/lustre/obdfilter/ ] && ONLINE=1
        # check OST is healthy
        fgrep -q "$SERVICE reported unhealthy" /proc/fs/lustre/health_check && HEALTH=1

        if [ $ONLINE ] && [ $HEALTH ]; then
	      echo "$SERVICE is online"
	      exit 0
	else
	      echo "$SERVICE is offline"
	      exit 1
	fi
}


# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	restart
	;;
  status)
	status
	;;
  *)
	echo "Usage: $SERVICE {start|stop|restart|status}"
	exit 1
esac

exit $RETVAL
