#!/bin/sh
#
# cachefilesd	Start up and shut down the cachefilesd daemon
#
### BEGIN INIT INFO
# Provides: fscache
# Required-Start: $local_fs $time
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Control the persistent network fs caching service
# Description: CacheFiles provides persistent local caching for network (and
#              other) filesystems in a directory on a locally mounted disk.
### END INIT INFO
#
# 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

RETVAL=0
CONFFILE=/etc/cachefilesd.conf
LOCKFILE=/var/lock/subsys/cachefilesd
PIDFILE=/var/run/cachefilesd.pid
OPTIONS="-f $CONFFILE"

SourceIfNotEmpty /etc/sysconfig/cachefilesd

start()
{
    modprobe cachefiles ||:
    start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- cachefilesd -p "$PIDFILE" $OPTIONS
    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
