diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-03-13 04:22:06 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-03-13 04:22:06 (GMT) |
commit | 33fd3033edccb73143223855f6f6f6305102d9d4 (patch) | |
tree | fac00827e5a28fd3b8bb2e64e9f4b1db3498393b | |
parent | 4c6858a1213d0b967aa767f6aca72e37b79cee8d (diff) |
use flock to lock multiple calls of the same importer, added sample cron config
-rw-r--r-- | cron | 7 | ||||
-rw-r--r-- | depends | 1 | ||||
-rwxr-xr-x | rhautoimport | 40 |
3 files changed, 30 insertions, 18 deletions
@@ -0,0 +1,7 @@ +# +# cron.d/rhautoimport -- scripts to import re-broadcasts +# +############## +# <show title> +27 18,19,20 * * 1-5 autoimport /usr/bin/rhautoimport-<code> +27 21 * * 1-5 autoimport /usr/bin/rhautoimport-<code> last @@ -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 |