aboutsummaryrefslogtreecommitdiffstats
path: root/main/djbdns/dnscache.initd
blob: 481022496ef93cbeba3bf025b47a260b6e9ca7b7 (plain) (blame)
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
59
#!/sbin/runscript
# control n instances of dnscache, without daemontools
# written for alpine linux - NBA April 2007

# -- Statrup variables 
UID=$( grep dnscache /etc/passwd | cut -f3 -d: )
GID=$( grep dnscache /etc/group | cut -f3 -d: )
ROOT=/etc/dnscache
DAEMON=/usr/bin/dnscache
VARRUN=/var/run/dnscache


#-----------------------------------------------------------------
# Main program

start() {
	
	ebegin "Starting dnscache"
	if [ -z "$UID" ] || [ -z "$GID" ]; then
		eend 1 "dnscache user or group missing"
		return 1
	fi
	
	# if its already running, just report it is
	if [ -e ${VARRUN}.pid ] && [ -d /proc/$( cat ${VARRUN}.pid ) ]; then
		eend 0
		return 0
	fi
	
	(
		export UID GID ROOT
		[ -n "$IPSEND" ] 	&& export IPSEND
		[ -n "$IP" ] 		&& export IP
		[ -n "$HIDETTL" ] 	&& export HIDETTL
		[ -n "$IPSEND" ] 	&& export IPSEND
		[ -n "$CACHESIZE" ] 	&& export CACHESIZE
		[ -n "$FORWARDONLY" ] 	&& export FORWARDONLY

		$DAEMON </dev/urandom >/dev/null 2>/dev/null &
		pid=$!
		sleep 1
		# Check if its still running
		if ! [ -d /proc/$pid ]; then
			$DAEMON </dev/urandom
			return 1
		fi
		echo $pid > ${VARRUN}.pid
		eend $?
		return 0
	)
}

stop() {
	ebegin "Stopping dnscache"
	start-stop-daemon --stop -m --pidfile ${VARRUN}.pid --oknodo \
		--exec $DAEMON && rm ${VARRUN}.pid
	eend $?
}