#!/sbin/openrc-run

description="9p socket proxy client"

depend()
{
	need 9pinit
}

start()
{

	[ -d /Socket ] || exit 0

	ebegin "Starting docker socket passthrough"

	[ -n "${PIDFILE}" ] || PIDFILE=/var/run/9pudc.pid
	[ -n "${LOGFILE}" ] || LOGFILE=/var/log/9pudc.log

	start-stop-daemon --start --quiet \
		--background \
		--exec /sbin/9pudc \
		--make-pidfile --pidfile ${PIDFILE} \
		--stderr "${LOGFILE}" --stdout "${LOGFILE}" \
		-- -path /Socket -sock /var/run/docker.sock

	eend $? "Failed to start 9pudc"
}

stop()
{
	[ -d /Socket ] || exit 0

	ebegin "Stopping docker socket passthrough"

	[ -n "${PIDFILE}" ] || PIDFILE=/var/run/9pudc.pid

	start-stop-daemon --stop --quiet --pidfile ${PIDFILE}

	eend $? "Failed to stop 9pudc"
}
