contrib/openrc-init: Add an OpenRC init script
authorW. Trevor King <wking@tremily.us>
Thu, 20 Feb 2014 23:06:13 +0000 (15:06 -0800)
committerW. Trevor King <wking@tremily.us>
Fri, 21 Feb 2014 02:23:48 +0000 (18:23 -0800)
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 [new file with mode: 0755]

diff --git a/contrib/openrc-init b/contrib/openrc-init
new file mode 100755 (executable)
index 0000000..49189ce
--- /dev/null
@@ -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 $?
+}