#!/bin/sh
#
# lxcfs	FUSE filesystem for LXC
#
# chkconfig: - 97 03
# description:	FUSE filesystem for LXC
# processname: lxcfs
# pidfile: /var/run/lxcfs.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

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

start()
{
        # Don't start if bind-mounted from host
        [ ! -d /var/lib/lxcfs/proc ] || exit 0

        # Cleanup in case of crash
        fusermount3 -u /var/lib/lxcfs 2> /dev/null ||:

	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --background --expect-user root -- \
		/usr/bin/lxcfs /var/lib/lxcfs
	RETVAL=$?
	return $RETVAL
}

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

restart()
{
	stop
	start
}

reload()
{
	msg_reloading lxcfs
	stop_daemon --pidfile "$PIDFILE" --expect-user root -USR1 -- /usr/bin/lxcfs
	RETVAL=$?
	return $RETVAL
}

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

exit $RETVAL
