added pid file support and timelimit

This commit is contained in:
mortzu 2014-09-19 21:39:47 +02:00
parent fa1302675d
commit d43d7783e9
1 changed files with 16 additions and 2 deletions

View File

@ -1,5 +1,8 @@
#! /usr/bin/env bash
# PID file
PID_FILE="/run/ffhb-update-dns.pid"
# getting workingdir of scripts
WORK_DIR="$(dirname $(readlink -nf $0))"
@ -22,13 +25,21 @@ fi
ZONEFILE=/var/cache/bind/ffhb.nodes.zone
RZONEFILE=/var/cache/bind/arpa.ip6.f.d.2.f.5.1.1.9.0.f.2.c.zone
# write run file
if [ -f "$PID_FILE" ]; then
echo "Script already running!" >&2
exit 1
else
touch "$PID_FILE"
fi
# loop until data received
while true; do
# increment counter
NUM=$(($NUM+1))
# get data from alfred
alfred-json -z -r 158 > "$TMP_FILE" 2>/dev/null
timeout -s KILL 30s alfred-json -z -r 158 >"$TMP_FILE" 2>/dev/null
# on success leave loop
if [ $? -eq 0 ]; then
@ -54,7 +65,7 @@ if zonegen.py < "$TMP_FILE" > "${ZONEFILE}.new"; then
fi
# generate reverse zone
if rzonegen.py 0.0.0.0.c.2.f.0.9.1.1.5.f.2.d.f.ip6.arpa < "$TMP_FILE" > "${RZONEFILE}.new"; then
if rzonegen.py 0.0.0.0.c.2.f.0.9.1.1.5.f.2.d.f.ip6.arpa <"$TMP_FILE" >"${RZONEFILE}.new"; then
mv "${RZONEFILE}.new" "${RZONEFILE}"
fi
@ -63,3 +74,6 @@ rndc reload >/dev/null
# remove tmp file
rm -f "$TMP_FILE"
# remove PID file
rm -f "$PID_FILE"