diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2009-07-24 08:01:31 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2009-07-24 08:01:31 +0000 |
commit | b70981b68efcce5256eb11c6cd26ae123b10b6ea (patch) | |
tree | a38be6efae5e2ba15c2e839504632f9b7bfd5f91 /main/djbdns/tinydns.initd | |
parent | 2b4df81538b8398442d5296650905c70341dd8d3 (diff) | |
download | aports-b70981b68efcce5256eb11c6cd26ae123b10b6ea.tar.bz2 aports-b70981b68efcce5256eb11c6cd26ae123b10b6ea.tar.xz |
moved extra/* to main/
and fixed misc build issues
Diffstat (limited to 'main/djbdns/tinydns.initd')
-rwxr-xr-x | main/djbdns/tinydns.initd | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/main/djbdns/tinydns.initd b/main/djbdns/tinydns.initd new file mode 100755 index 000000000..a68474c4e --- /dev/null +++ b/main/djbdns/tinydns.initd @@ -0,0 +1,87 @@ +#!/sbin/runscript +# control an instance of tinydns, without daemontools +# written for alpine linux - NBA April 2007 + +opts="reload" + +# -- Statrup variables +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" + UID=$( grep tinydns /etc/passwd | cut -f3 -d: ) + GID=$( grep tinydns /etc/group | cut -f3 -d: ) + + # 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 [ -z "$IP" ]; then + eend 1 "IP is not specified in /etc/conf.d/$SVCNAME" + return 1 + fi + + start-stop-daemon --start --env "UID=$UID" --env "GID=$GID" \ + --env "ROOT=$ROOT" --env "IP=$IP" --pidfile ${VARRUN}.pid \ + --background --make-pidfile --exec $DAEMON + eend $? +} + +stop() { + ebegin "Stopping tinydns" + start-stop-daemon --stop --pidfile ${VARRUN}.pid --exec $DAEMON + eend $? +} + |