49189ce113dfbc66defcd7639971413e68b5b54c
[package-cache.git] / contrib / openrc-init
1 #!/sbin/runscript
2
3 PC_USER="${PC_USER:-package-cache}"
4 PC_GROUP="${PC_GROUP:-portage}"
5 CACHE_DIR="${CACHE_DIR:-/usr/portage/distfiles}"
6 HOST="${HOST:-0.0.0.0}"
7 PORT="${PORT:-4000}"
8 SOURCES="${SOURCES:-http://distfiles.gentoo.org/distfiles}"
9 SOURCE_OPTS=()
10 for SOURCE in ${SOURCES}
11 do
12         SOURCE_OPTS+=( --source "${SOURCE}" )
13 done
14 command="/usr/bin/package-cache"
15 pidfile="/run/${SVCNAME}.pid"
16
17 depend() {
18         need net
19 }
20
21 start() {
22         ebegin "Starting ${SVCNAME}"
23         if [[ ! -d "${CACHE_DIR}" ]]; then
24                 mkdir -p "${CACHE_DIR}"
25                 chown "${PC_USER}:${PC_GROUP}" "${CACHE_DIR}"
26         fi
27         start-stop-daemon --start \
28                 --user "${PC_USER}:${PC_GROUP}" \
29                 --chdir "${CACHE_DIR}" \
30                 --exec "${command}" \
31                 --background \
32                 --pidfile "${pidfile}" \
33                 --make-pidfile \
34                 -- \
35                 --syslog \
36                 --host "${HOST}" \
37                 --port "${PORT}" \
38                 "${SOURCE_OPTS[@]}" \
39                 --cache "${CACHE_DIR}"
40         eend $?
41 }
42
43 stop() {
44         ebegin "Stopping ${SVCNAME}"
45         start-stop-daemon --stop \
46                 --user "${PC_USER}:${PC_GROUP}" \
47                 --exec "${command}" \
48                 --pidfile "${pidfile}"
49         eend $?
50 }