From cd20dd71057d31049f769a5e8da016ce77aa25d0 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 20 Feb 2014 15:06:13 -0800 Subject: [PATCH] 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 --- contrib/openrc-init | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 contrib/openrc-init 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 $? +} -- 2.26.2