#!/bin/sh
#
# cachefilesd	Start up and shut down the cachefilesd daemon
#
# chkconfig:	- 13 87
# description:	Starts user-level daemon that manages the caching files \
#	      	used by Network Filsystems
# processname:	cachefilesd
# config:	/etc/cachefilesd.conf
# pidfile:	/var/run/cachefilesd.pid

WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
SourceIfNotEmpty /etc/sysconfig/network && [ "$NETWORKING" != no ] || exit

PIDFILE=/var/run/cachefilesd.pid
LOCKFILE=/var/lock/subsys/cachefilesd
RETVAL=0

start()
{
    modprobe cachefiles ||:
    start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- cachefilesd -p "$PIDFILE"
    RETVAL=$?
    return $RETVAL
}

stop()
{
    stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root cachefilesd
    RETVAL=$?
    return $RETVAL
}

restart()
{
    stop
    start
}

# See how we were called.
case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart|reload)
    restart
    ;;
    condstop)
    if [ -e "$LOCKFILE" ]; then
	stop
    fi
    ;;
    condrestart|condreload)
    if [ -e "$LOCKFILE" ]; then
	restart
    fi
    ;;
    status)
    status --pidfile "$PIDFILE" --expect-user root cachefilesd
    RETVAL=$?
    ;;
    *)
    msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
    RETVAL=1
esac

exit $RETVAL
