#!/bin/bash

# Keep the following services in proper shutdown order
# (Check with the start/stop numbers in the init file)
#
# NOTE: This seems to work. Moving netfs at the end does not work.
#       If you modify this, test-test-test...
#SERVICES="rpcidmapd rpcgssd nfslock rpcbind"
SERVICES="nfs-idmapd rpc-gssd nfs-lock rpcbind"

stop() {
    echo "STOPPING ESAME-NFS"
    if [ ${ESAME_NFS} -eq 0 ]; then
        sync
        umount /home
        for i in ${SERVICES}; do
            service "$i" stop
        done
    fi
}

start() {
    echo "STARTING ESAME-NFS"
    if [ ${ESAME_NFS} -eq 1 ]; then
        for i in ${SERVICES}; do
            service "$i" start
        done
        mount /home
    else
        stop
    fi
}

case "$1" in
'start')
    start
    ;;
'stop')
    stop
    ;;
'restart')
    stop
    start
    ;;
*)
    echo "Usage: $0 { start | stop | restart }";
    exit 1;
    ;;
esac

exit 0