contrib/openrc/init.d/package-cache: Don't include 'distfiles' in source
[package-cache.git] / contrib / openrc / init.d / package-cache
1 #!/sbin/runscript
2
3 PC_USER="${PC_USER:-package-cache}"
4 PC_GROUP="${PC_GROUP:-portage}"
5 CACHE_DIR="${CACHE_DIR:-/usr/portage}"
6 HOST="${HOST:-0.0.0.0}"
7 PORT="${PORT:-4000}"
8 SOURCES="${SOURCES:-http://distfiles.gentoo.org}"
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                 ${PC_OPTS:+${PC_OPTS}}
41         eend $?
42 }
43
44 stop() {
45         ebegin "Stopping ${SVCNAME}"
46         start-stop-daemon --stop \
47                 --user "${PC_USER}:${PC_GROUP}" \
48                 --exec "${command}" \
49                 --pidfile "${pidfile}"
50         eend $?
51 }