From: W. Trevor King Date: Thu, 20 Feb 2014 23:06:13 +0000 (-0800) Subject: contrib/openrc-init: Add an OpenRC init script X-Git-Tag: v0.1~9 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cd20dd71057d31049f769a5e8da016ce77aa25d0;p=package-cache.git contrib/openrc-init: Add an OpenRC init script References: http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=4#doc_chap4 https://wiki.gentoo.org/wiki/OpenRC --- diff --git a/contrib/openrc-init b/contrib/openrc-init new file mode 100755 index 0000000..49189ce --- /dev/null +++ b/contrib/openrc-init @@ -0,0 +1,50 @@ +#!/sbin/runscript + +PC_USER="${PC_USER:-package-cache}" +PC_GROUP="${PC_GROUP:-portage}" +CACHE_DIR="${CACHE_DIR:-/usr/portage/distfiles}" +HOST="${HOST:-0.0.0.0}" +PORT="${PORT:-4000}" +SOURCES="${SOURCES:-http://distfiles.gentoo.org/distfiles}" +SOURCE_OPTS=() +for SOURCE in ${SOURCES} +do + SOURCE_OPTS+=( --source "${SOURCE}" ) +done +command="/usr/bin/package-cache" +pidfile="/run/${SVCNAME}.pid" + +depend() { + need net +} + +start() { + ebegin "Starting ${SVCNAME}" + if [[ ! -d "${CACHE_DIR}" ]]; then + mkdir -p "${CACHE_DIR}" + chown "${PC_USER}:${PC_GROUP}" "${CACHE_DIR}" + fi + start-stop-daemon --start \ + --user "${PC_USER}:${PC_GROUP}" \ + --chdir "${CACHE_DIR}" \ + --exec "${command}" \ + --background \ + --pidfile "${pidfile}" \ + --make-pidfile \ + -- \ + --syslog \ + --host "${HOST}" \ + --port "${PORT}" \ + "${SOURCE_OPTS[@]}" \ + --cache "${CACHE_DIR}" + eend $? +} + +stop() { + ebegin "Stopping ${SVCNAME}" + start-stop-daemon --stop \ + --user "${PC_USER}:${PC_GROUP}" \ + --exec "${command}" \ + --pidfile "${pidfile}" + eend $? +}