introduced trap to reduce redunant code
This commit is contained in:
parent
c4d923240b
commit
4b18998873
|
@ -28,7 +28,7 @@
|
||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
# PID file
|
# PID file
|
||||||
PID_FILE="/run/ffhb-update-dns.pid"
|
RUN_FILE='/run/ffhb-update-dns.run'
|
||||||
|
|
||||||
# getting workingdir of scripts
|
# getting workingdir of scripts
|
||||||
WORK_DIR="$(dirname $(readlink -nf $0))"
|
WORK_DIR="$(dirname $(readlink -nf $0))"
|
||||||
|
@ -52,12 +52,23 @@ fi
|
||||||
ZONEFILE=/var/cache/bind/ffhb.nodes.zone
|
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
|
RZONEFILE=/var/cache/bind/arpa.ip6.f.d.2.f.5.1.1.9.0.f.2.c.zone
|
||||||
|
|
||||||
|
function on_exit() {
|
||||||
|
# remove tmp files
|
||||||
|
for FILE in "$TMP_FILE" "$RUN_FILE"; do
|
||||||
|
if [ -n "$FILE" ]; then
|
||||||
|
rm -f "$FILE"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
trap on_exit EXIT SIGTERM SIGINT
|
||||||
|
|
||||||
# write run file
|
# write run file
|
||||||
if [ -f "$PID_FILE" ]; then
|
if [ -f "$RUN_FILE" ]; then
|
||||||
echo "Script already running!" >&2
|
echo 'Script already running!' >&2
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
touch "$PID_FILE"
|
touch "$RUN_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# loop until data received
|
# loop until data received
|
||||||
|
@ -76,9 +87,6 @@ while true; do
|
||||||
|
|
||||||
# if the 240th run has reached kill script
|
# if the 240th run has reached kill script
|
||||||
if [ $NUM -gt 240 ]; then
|
if [ $NUM -gt 240 ]; then
|
||||||
# remove tmp file
|
|
||||||
rm -f "$TMP_FILE"
|
|
||||||
|
|
||||||
# exit with error code
|
# exit with error code
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -99,9 +107,3 @@ fi
|
||||||
|
|
||||||
# reload nameserver
|
# reload nameserver
|
||||||
rndc reload >/dev/null
|
rndc reload >/dev/null
|
||||||
|
|
||||||
# remove tmp file
|
|
||||||
rm -f "$TMP_FILE"
|
|
||||||
|
|
||||||
# remove PID file
|
|
||||||
rm -f "$PID_FILE"
|
|
||||||
|
|
Loading…
Reference in New Issue