blob: 396b8ab33bb6a870f546fc899270edeebffdebd8 (
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#!/sbin/runscript
# control an instance of tinydns, without daemontools
# written for alpine linux - NBA April 2007
opts="reload"
# -- Statrup variables
UID=$( grep tinydns /etc/passwd | cut -f3 -d: )
GID=$( grep tinydns /etc/group | cut -f3 -d: )
DAEMON=/usr/bin/tinydns
COMPILER=/usr/bin/tinydns-data
IFACE="${SVCNAME#*.}"
if [ -n "$IFACE" ] && [ "${SVCNAME}" != "tinydns" ]; then
ROOT=${ROOT:-/var/cache/tinydns.$IFACE}
VARRUN=${VARRUN:-/var/run/tinydns.$IFACE}
DATADIR=${DATADIR:-/etc/tinydns.$IFACE}
else
ROOT=${ROOT:-/var/cache/tinydns}
VARRUN=${VARRUN:-/var/run/tinydns}
DATADIR=${DATADIR:-/etc/tinydns}
fi
#-----------------------------------------------------------------
# Main program
reload() {
local rc opwd="$opwd"
# Create the $ROOT directory if necessary
if [ ! -d "$ROOT" ]; then
mkdir -p "$ROOT"
chown $UID:$GID "$ROOT"
fi
# If a file named "data" exists in the $ROOT dir
# Then we just use it and ignore anything else
# If the "data" file does not exist, we attempt
# to build one out of the "zone files".
ebegin "Generating tinydns cache"
rm -f "$ROOT/data"
if [ -e $DATADIR/data ]; then
ln -sf "$DATADIR/data" "$ROOT/data"
else
set -- $( find $DATADIR -type f )
if [ $# -eq 0 ]; then
eend 1 "Missing data or zone files in $DATADIR"
return 1
fi
cat "$@" > "$ROOT/data"
fi
cd "$ROOT" || return 1
[ -e data ] || rm -f data.cdb
$COMPILER
rc=$?
cd "$opwd"
eend $rc
return $rc
}
start() {
# Always do a reload on start
reload || return 1
ebegin "Starting tinydns"
if [ -z "$UID" ] || [ -z "$GID" ]; then
eend 1 "tinydns 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
if [ -z "$IP" ]; then
eend 1 "IP is not specified in /etc/conf.d/$SVCNAME"
return 1
fi
(
export UID GID ROOT IP
$DAEMON >/dev/null 2>/dev/null &
pid=$!
sleep 1
# Check if its still running
if ! [ -d /proc/$pid ]; then
rm ${VARRUN}.pid
$DAEMON
return 1
fi
echo $pid > ${VARRUN}.pid
)
eend $?
return 0
}
stop() {
ebegin "Stopping tinydns"
start-stop-daemon --stop --pidfile ${VARRUN}.pid --oknodo \
--exec $DAEMON && rm ${VARRUN}.pid
eend $?
}
|