Last active
March 30, 2019 13:54
-
-
Save job/c9d4bbec32bc3153662eae024056686f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# script maintained by Job Snijders job@ntt.net | |
# Lock | |
LOCKFILE="/var/lock/`basename $0`" | |
LOCKFD=99 | |
_lock() { flock -$1 $LOCKFD; } | |
_no_more_locking() { _lock u; _lock xn && rm -f $LOCKFILE; } | |
_prepare_locking() { eval "exec $LOCKFD>\"$LOCKFILE\""; trap _no_more_locking EXIT; } | |
_prepare_locking | |
exlock_now() { _lock xn; } # obtain an exclusive lock immediately or fail | |
unlock() { _lock u; } # drop a lock | |
exlock_now || { | |
echo "ERROR: `basename $0` already running!" | |
exit 1 | |
} | |
WAITPERIOD=$((RANDOM % 150)) | |
echo "Waiting ${WAITPERIOD} seconds..." && sleep ${WAITPERIOD} | |
/root/.cargo/bin/routinator -v update | |
/root/.cargo/bin/routinator -v vrps -n -f json -o /var/www/html/export.json.tmp && mv /var/www/html/export.json.tmp /var/www/html/export.json | |
/root/.cargo/bin/routinator -v vrps -n -f rpsl -o /var/www/html/export.rpsl.tmp && mv /var/www/html/export.rpsl.tmp /var/www/html/export.rpsl | |
unlock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment