From 33fd3033edccb73143223855f6f6f6305102d9d4 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 13 Mar 2016 05:22:06 +0100 Subject: use flock to lock multiple calls of the same importer, added sample cron config diff --git a/cron b/cron new file mode 100644 index 0000000..a368877 --- /dev/null +++ b/cron @@ -0,0 +1,7 @@ +# +# cron.d/rhautoimport -- scripts to import re-broadcasts +# +############## +# +27 18,19,20 * * 1-5 autoimport /usr/bin/rhautoimport- +27 21 * * 1-5 autoimport /usr/bin/rhautoimport- last diff --git a/depends b/depends index 57d9253..c97c1dc 100644 --- a/depends +++ b/depends @@ -6,3 +6,4 @@ liburi-perl libwww-perl libxml-feed-perl perl +util-linux diff --git a/rhautoimport b/rhautoimport index 2518231..7ae49ee 100755 --- a/rhautoimport +++ b/rhautoimport @@ -61,24 +61,28 @@ if [ -z "$MAIL_TO" ]; then MAIL_TO="root" fi -/usr/bin/rhautoimport-$1 ${@:2} > $LOG_FILE 2>&1 -case $? in - 0) - mail -a "Content-Type: text/plain; charset=utf-8" -s "$TITLE - Imported Successfully" $MAIL_TO < $LOG_FILE - ;; - 42) - # do nothing - the script didn't import anything but no message should be sent - ;; - *) - if [ "$2" == 'last' ]; then - subject="$TITLE - Import Error - last attempt!!!" - else - subject="$TITLE - Import Error - will retry" - fi - mail -a "Content-Type: text/plain; charset=utf-8" -s "$subject" $MAIL_TO < $LOG_FILE - ;; -esac +( + /usr/bin/flock -x -w 10 200 + + /usr/bin/rhautoimport-$1 ${@:2} > $LOG_FILE 2>&1 + case $? in + 0) + mail -a "Content-Type: text/plain; charset=utf-8" -s "$TITLE - Imported Successfully" $MAIL_TO < $LOG_FILE + ;; + 42) + # do nothing - the script didn't import anything but no message should be sent + ;; + *) + if [ "$2" == 'last' ]; then + subject="$TITLE - Import Error - last attempt!!!" + else + subject="$TITLE - Import Error - will retry" + fi + mail -a "Content-Type: text/plain; charset=utf-8" -s "$subject" $MAIL_TO < $LOG_FILE + ;; + esac + rm -f $LOG_FILE -rm -f $LOG_FILE +) 200>/var/lock/rhautoimport-$1.lock exit 0 -- cgit v0.10.2