summaryrefslogtreecommitdiff
path: root/net-analyzer/darkstat/files/darkstat-initd
blob: c362251dadc83c1a98096d6193714e5072cef2ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/sbin/openrc-run
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2 

IF=${SVCNAME##*.}

if [ -n "${IF}" -a "${SVCNAME}" != "darkstat" ] ; then
	PIDFILE=/run/darkstat.${IF}.pid
else
	PIDFILE=/run/darkstat.pid
fi

depend() {
        need net
}

chkconfig() {
	if [ -n "${IF}" -a "${SVCNAME}" != "darkstat" ] ; then
		if [ ! -f "/etc/conf.d/darkstat.${IF}" ] ; then
			einfo "It's possible to have distinct config in /etc/conf.d/darkstat.${IF}."
		fi
		INTERFACE=${IF}
	else
		if [ ! -f "/etc/conf.d/darkstat" ] ; then
			ewarn "/etc/conf.d/darkstat does not exist. Falling on defaults."
		fi
	fi

	if [ -z "${INTERFACE}" ]; then
		ewarn "No interface specified. Trying to use eth0."
		INTERFACE="eth0"
	fi

	DARK_OPTS="-i ${INTERFACE}"
	[ -n "${PORT}" ] && DARK_OPTS="${DARK_OPTS} -p ${PORT}"
	[ -n "${ADDRESS}" ] && DARK_OPTS="${DARK_OPTS} -b ${ADDRESS}"
	[ -n "${DAYLOGFILE}" ] && DARK_OPTS="${DARK_OPTS} --daylog ${DAYLOGFILE}"

	return 0
}

start() {
	chkconfig || return 1

	# If ${PIDFILE} exist darkstat fails to start
	[ -f ${PIDFILE} ] && rm ${PIDFILE}
	ebegin "Starting darkstat on ${INTERFACE}"
	/sbin/start-stop-daemon --start --exec /usr/sbin/darkstat -- \
		--chroot "${CHROOT:-__CHROOT__}" --pidfile ${PIDFILE} \
		${DARKSTAT_OPTS} ${DARK_OPTS} -f "${FILTER}"
	eend $?
}

stop() {
	ebegin "Stopping darkstat on ${INTERFACE}"
	/sbin/start-stop-daemon --stop --pidfile ${PIDFILE}
	eend $?
}