summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-03-15 22:02:41 +0100
committersyncer <root@plopp.spline.de>2012-03-15 22:02:41 +0100
commit6e1dd2516f260a0361d65b58509106a615d0c149 (patch)
treeffd6c02e8b1b21e3182a3ed502f8644898d4db98
parent657d1fc484fa0b21b979525a92ace5c9e6f63da2 (diff)
downloadmirror-sync-6e1dd2516f260a0361d65b58509106a615d0c149.tar.gz
mirror-sync-6e1dd2516f260a0361d65b58509106a615d0c149.tar.bz2
mirror-sync-6e1dd2516f260a0361d65b58509106a615d0c149.zip
syncer scripts: move locking to cronwrapper
now lockfile-progs is used as replacement for the lockfile command of procmail
-rwxr-xr-xbin/cron_wrapper.sh12
-rwxr-xr-xbin/sync-archlinux.sh10
-rwxr-xr-xbin/sync-crux.sh10
-rwxr-xr-xbin/sync-dhozac.sh10
-rwxr-xr-xbin/sync-dslinux-svn-repo.sh9
-rwxr-xr-xbin/sync-gentoo-ftp-mirror.sh10
-rwxr-xr-xbin/sync-gentoo-portage.sh11
-rwxr-xr-xbin/sync-openbsd-cvs-repo.sh4
-rwxr-xr-xbin/sync-openbsd-ftp-tree.sh3
-rwxr-xr-xbin/sync-osm-planet.sh68
-rwxr-xr-xbin/sync-siduction.sh10
-rwxr-xr-xbin/sync-tor.sh10
12 files changed, 57 insertions, 110 deletions
diff --git a/bin/cron_wrapper.sh b/bin/cron_wrapper.sh
index 4e25802..82dea79 100755
--- a/bin/cron_wrapper.sh
+++ b/bin/cron_wrapper.sh
@@ -39,6 +39,7 @@ CRON_SCRIPT_BASENAME="$(basename ${CRON_SCRIPT} ".sh")"
CRON_SCRIPT_LOGNAME="${CRON_SCRIPT_BASENAME#sync-}"
ERROR_LOG="/var/log/sync/${CRON_SCRIPT_LOGNAME}_error.log"
LOG="/var/log/sync/${CRON_SCRIPT_LOGNAME}.log"
+LOCKFILE="/var/lock/$(basename $0)"
create_and_check_log "${ERROR_LOG}"
create_and_check_log "${LOG}"
@@ -49,6 +50,12 @@ ERROR_TMP=$(mktemp -t "${CRON_SCRIPT_BASENAME}.XXXXXXXX")
# damit der cronscript dateiname nicht mehr enthalten ist
shift 1
+# locking, cron script should not executed while the last
+# instance is running
+lockfile-create "$LOCKFILE" || exit 1
+lockfile-touch "$LOCKFILE" &
+TOUCH="$!"
+
# log header
LOG_HEADER="-------------------- $(date) --------------------"
echo "${LOG_HEADER}" >> "${LOG}"
@@ -58,7 +65,6 @@ ${CRON_SCRIPT} $@ >> "${LOG}" 2> "${ERROR_TMP}"
if [ $(grep -v "^\s*$" "${ERROR_TMP}" | wc -l) -gt 0 ]
then
-
if [ "$(date -r${ERROR_LOG} +%F)" != "$(date +%F)" ]
then
cat "${ERROR_LOG}"
@@ -72,3 +78,7 @@ then
fi
rm "${ERROR_TMP}"
+
+# cleanup lockfile
+kill "$TOUCH"
+lockfile-remove "$LOCKFILE"
diff --git a/bin/sync-archlinux.sh b/bin/sync-archlinux.sh
index fd03d23..f531fa3 100755
--- a/bin/sync-archlinux.sh
+++ b/bin/sync-archlinux.sh
@@ -5,11 +5,5 @@ OPTS="-rtlvH --delete-after --delay-updates --safe-links --max-delete=1000" # fr
SRC="rsync://ftp5.gwdg.de/pub/linux/archlinux/"
DST="/mirror/ftp/pub/archlinux/"
-lockfile=/tmp/`basename $0`.lock
-
-if lockfile -r 5 $lockfile
-then
- ${RSYNC} ${OPTS} ${SRC} ${DST}
- echo "End: "`date`
- rm -f $lockfile
-fi
+${RSYNC} ${OPTS} ${SRC} ${DST}
+echo "End: "`date`
diff --git a/bin/sync-crux.sh b/bin/sync-crux.sh
index 9b14f6b..30c52a8 100755
--- a/bin/sync-crux.sh
+++ b/bin/sync-crux.sh
@@ -5,11 +5,5 @@ OPTS="--quiet --recursive --links --perms --times --devices --delete --timeout=6
SRC="rsync://rsync.crux.nu/crux/"
DST="/mirror/ftp/pub/crux/"
-lockfile=/tmp/`basename $0`.lock
-
-if lockfile -r 5 $lockfile
-then
- ${RSYNC} ${OPTS} ${SRC} ${DST}
- echo "End: "`date`
- rm -f $lockfile
-fi
+${RSYNC} ${OPTS} ${SRC} ${DST}
+echo "End: "`date`
diff --git a/bin/sync-dhozac.sh b/bin/sync-dhozac.sh
index 7229e40..c5a3eab 100755
--- a/bin/sync-dhozac.sh
+++ b/bin/sync-dhozac.sh
@@ -5,11 +5,5 @@ OPTS="-Hax --delete --exclude=/plague/tmp"
SRC="rsync://rpm.hozac.com/dhozac/"
DST="/mirror/ftp/pub/dhozac/"
-lockfile=/tmp/`basename $0`.lock
-
-if lockfile -r 5 $lockfile
-then
- ${RSYNC} ${OPTS} ${SRC} ${DST} && date > "${DST}/lastsync"
- echo "End: "`date`
- rm -f $lockfile
-fi
+${RSYNC} ${OPTS} ${SRC} ${DST} && date > "${DST}/lastsync"
+echo "End: "`date`
diff --git a/bin/sync-dslinux-svn-repo.sh b/bin/sync-dslinux-svn-repo.sh
index c302be6..92d9d74 100755
--- a/bin/sync-dslinux-svn-repo.sh
+++ b/bin/sync-dslinux-svn-repo.sh
@@ -8,11 +8,4 @@
ANONSVN_HOME=/raid/anonsvn
SVN_ROOTDIR=$ANONSVN_HOME/dslinux
-lockfile=/tmp/`basename $0`.lock
-
-if lockfile -r 5 $lockfile
-then
- (cd $SVN_ROOTDIR && rsync -q -z -a --delete rsync://pferd.in-berlin.de/dslinuxsvn/ .)
- rm -f $lockfile
-fi
-
+(cd $SVN_ROOTDIR && rsync -q -z -a --delete rsync://pferd.in-berlin.de/dslinuxsvn/ .)
diff --git a/bin/sync-gentoo-ftp-mirror.sh b/bin/sync-gentoo-ftp-mirror.sh
index 74d9cdc..d6660f5 100755
--- a/bin/sync-gentoo-ftp-mirror.sh
+++ b/bin/sync-gentoo-ftp-mirror.sh
@@ -5,11 +5,5 @@ OPTS="--quiet --recursive --links --perms --times --devices --delete --timeout=6
SRC="gentoo@masterdistfiles.gentoo.org::gentoo"
DST="/raid/ftp/pub/gentoo/"
-lockfile=/tmp/`basename $0`.lock
-
-if lockfile -r 5 $lockfile
-then
- ${RSYNC} ${OPTS} ${SRC} ${DST}
- echo "End: "`date`
- rm -f $lockfile
-fi
+${RSYNC} ${OPTS} ${SRC} ${DST}
+echo "End: "`date`
diff --git a/bin/sync-gentoo-portage.sh b/bin/sync-gentoo-portage.sh
index 3f8c552..e9ca82b 100755
--- a/bin/sync-gentoo-portage.sh
+++ b/bin/sync-gentoo-portage.sh
@@ -5,12 +5,5 @@ OPTS="--quiet --recursive --links --perms --times --devices --compress --delete
SRC="rsync://masterportage.gentoo.org/gentoo-portage"
DST="/raid/gentoo-portage/"
-lockfile=/tmp/`basename $0`.lock
-
-if lockfile -r 5 $lockfile
-then
- ${RSYNC} ${OPTS} ${SRC} ${DST}
- echo "End: "`date`
- rm -f $lockfile
-fi
-
+${RSYNC} ${OPTS} ${SRC} ${DST}
+echo "End: "`date`
diff --git a/bin/sync-openbsd-cvs-repo.sh b/bin/sync-openbsd-cvs-repo.sh
index cc546ff..5a58289 100755
--- a/bin/sync-openbsd-cvs-repo.sh
+++ b/bin/sync-openbsd-cvs-repo.sh
@@ -6,9 +6,7 @@
#logger "`basename $0`: invoked `date`"
CVS_ROOTDIR=/raid/anoncvs/OpenBSD/cvs
-LOCKFILE=/tmp/`basename ${0}`.lock
-lockfile -r 3 ${LOCKFILE} || exit 1
(cd $CVS_ROOTDIR && \
rsync -q -a --recursive --times --links --hard-links --delete \
--exclude=CVSROOT/history \
@@ -26,5 +24,3 @@ echo "" > $CVS_ROOTDIR/CVSROOT/config
# One line in the modules file breaks checkouts,
# due to debian bug #226888. Comment it out. --stsp
sed -i -e 's/\(^www.*-i.*\)/#\1/' $CVS_ROOTDIR/CVSROOT/modules
-
-rm -f ${LOCKFILE}
diff --git a/bin/sync-openbsd-ftp-tree.sh b/bin/sync-openbsd-ftp-tree.sh
index ed0ddcc..0a8074e 100755
--- a/bin/sync-openbsd-ftp-tree.sh
+++ b/bin/sync-openbsd-ftp-tree.sh
@@ -3,7 +3,6 @@
# See http://www.openbsd.org/ftp.html for up-to-date mirror list!
REMOTE=rsync://ftp.eu.openbsd.org/OpenBSD/
PUBDIR=/raid/ftp/pub/OpenBSD
-LOCKFILE=/tmp/`basename ${0}`.lock
if [ "$1" = "-v" ]; then
verbose="-v"
@@ -11,7 +10,6 @@ else
verbose="-q"
fi
-lockfile -r 3 ${LOCKFILE} || exit 1
rsync $verbose -a -i --recursive --times --links --hard-links --delete \
--exclude="/[2-3].[0-9]" \
--exclude="/4.[0-8]" \
@@ -21,4 +19,3 @@ rsync $verbose -a -i --recursive --times --links --hard-links --delete \
--exclude="/README" \
--exclude="/README~" \
${REMOTE} ${PUBDIR}
-rm -f ${LOCKFILE}
diff --git a/bin/sync-osm-planet.sh b/bin/sync-osm-planet.sh
index 878ad5b..df9b538 100755
--- a/bin/sync-osm-planet.sh
+++ b/bin/sync-osm-planet.sh
@@ -22,43 +22,37 @@ TRACKER=(
"udp://tracker.openbittorrent.com:80/announce" )
MKTORRENT_OPTS=( "-l 22" )
-lockfile=/tmp/`basename $0`.lock
-
-if lockfile -r 5 $lockfile
-then
- ${RSYNC} "${RSYNC_OPTS[@]}" ${SRC} ${DST}
-
- # create torrents
- for file in ${DST}/*.bz2
- do
- archiv="$(basename $file)"
- if [ ! -L ${file} ]
+${RSYNC} "${RSYNC_OPTS[@]}" ${SRC} ${DST}
+
+# create torrents
+for file in ${DST}/*.bz2
+do
+ archiv="$(basename $file)"
+ if [ ! -L ${file} ]
+ then
+ torrent="${DST}/torrents/${archiv}.torrent"
+ torrent_tmp="/tmp/${archiv}.torrent"
+
+ if [ ! -e "${torrent}" ]
then
- torrent="${DST}/torrents/${archiv}.torrent"
- torrent_tmp="/tmp/${archiv}.torrent"
-
- if [ ! -e "${torrent}" ]
- then
- rm -f "${torrent_tmp}"
-
- TRACKER_OPT=""
- for t in "${TRACKER[@]}"
- do
- TRACKER_OPT="${TRACKER_OPT} -a ${t}"
- done
-
- ${MKTORRENT} ${TRACKER_OPT} "${MKTORRENT_OPTS[@]}" \
- -w "http://ftp.spline.inf.fu-berlin.de/pub/openstreetmap/${archiv}" \
- -w "http://planet.osm.org/${archiv}" \
- "${file}" -o "${torrent_tmp}" > /dev/null && \
- mv "${torrent_tmp}" "${torrent}"
- fi
- else
- target="$(readlink ${file})"
- ln -sf "$(basename ${target}).torrent" "${DST}/torrents/${archiv}.torrent"
+ rm -f "${torrent_tmp}"
+
+ TRACKER_OPT=""
+ for t in "${TRACKER[@]}"
+ do
+ TRACKER_OPT="${TRACKER_OPT} -a ${t}"
+ done
+
+ ${MKTORRENT} ${TRACKER_OPT} "${MKTORRENT_OPTS[@]}" \
+ -w "http://ftp.spline.inf.fu-berlin.de/pub/openstreetmap/${archiv}" \
+ -w "http://planet.osm.org/${archiv}" \
+ "${file}" -o "${torrent_tmp}" > /dev/null && \
+ mv "${torrent_tmp}" "${torrent}"
fi
- done
+ else
+ target="$(readlink ${file})"
+ ln -sf "$(basename ${target}).torrent" "${DST}/torrents/${archiv}.torrent"
+ fi
+done
- echo "End: $(date)"
- rm -f $lockfile
-fi
+echo "End: $(date)"
diff --git a/bin/sync-siduction.sh b/bin/sync-siduction.sh
index 997e0ec..9297ceb 100755
--- a/bin/sync-siduction.sh
+++ b/bin/sync-siduction.sh
@@ -6,11 +6,5 @@ OPTS="-prtlvH --delete-after --delay-updates --safe-links"
SRC="rsync://sync.siduction.org:/siduction"
DST="/mirror/ftp/pub/siduction/"
-lockfile=/tmp/`basename $0`.lock
-
-if lockfile -r 5 $lockfile
-then
- ${RSYNC} ${OPTS} ${SRC} ${DST}
- echo "End: "`date`
- rm -f $lockfile
-fi
+${RSYNC} ${OPTS} ${SRC} ${DST}
+echo "End: "`date`
diff --git a/bin/sync-tor.sh b/bin/sync-tor.sh
index d1df555..4c74407 100755
--- a/bin/sync-tor.sh
+++ b/bin/sync-tor.sh
@@ -5,11 +5,5 @@ OPTS="-a --quiet --delete --timeout=600"
SRC="rsync://rsync.torproject.org/tor"
DST="/mirror/ftp/pub/tor"
-lockfile=/tmp/`basename $0`.lock
-
-if lockfile -r 5 $lockfile
-then
- ${RSYNC} ${OPTS} ${SRC} ${DST}
- echo "End: "`date`
- rm -f $lockfile
-fi
+${RSYNC} ${OPTS} ${SRC} ${DST}
+echo "End: "`date`