#!/bin/sh
#
# rozofs-rozofsmount    This shell script takes care of starting and stopping
#                       the rozofs-rozofsmount services.
#
#chkconfig: 35 80 20
#description: rozofs-rozofsmount
#processname: rozofsmount

### BEGIN INIT INFO
# Provides:          rozofsmount
# Required-Start:    $network $local_fs $portmap
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: RozoFS rozofsmount
# Description:       RozoFS is a scale-out NAS file system. This service
#                    provides the rozofsmount functionality.
### END INIT INFO

DAEMON=/bin/mount.rozofs

# Source function library.
if [ -f /lib/lsb/init-functions ]; then
	. /lib/lsb/init-functions
	alias START_DAEMON=start_daemon
    alias STATUS=exportd_status
    alias LOG_SUCCESS=log_success_msg
    alias LOG_FAILURE=log_failure_msg
    alias LOG_WARNING=log_warning_msg
elif [ -f /etc/init.d/functions ]; then
    . /etc/init.d/functions
    alias START_DAEMON=daemon
    alias STATUS=status
    alias LOG_SUCCESS=success
    alias LOG_FAILURE=failure
    alias LOG_WARNING=passed
else
    echo "Error: your platform is not supported by $0" > /dev/stderr
    exit 1
fi

# See how we were called.
case "$1" in
  start)
        [ -x ${DAEMON} ] || exit 5

        # Start daemons.
        echo -n $"Mounting rozofs filesystems: "
        mount -a -t rozofs
        case "$?" in
            0) LOG_SUCCESS ;;
            *) LOG_FAILURE ;;
        esac
    	;;

  stop)
        [ -f /etc/fstab ] || return
        #
        # Read through fstab line by line. If it is ROZOFS, mount it
        #

        exec 9<&0 </etc/fstab

        while read DEV MTPT FSTYPE OPTS REST
        do
        case "$DEV" in
            ""|\#*)
                continue;
                ;;
            "rozofsmount")
                umount $MTPT
        		case "$?" in
            		0) LOG_SUCCESS ;;
            		*) LOG_FAILURE ;;
        		esac
    		;;
        esac
        done

        exec 0<&9 9<&-
  *)
        echo $"Usage: exportd {start}"
        RETVAL=1
        ;;
esac

exit $RETVAL
