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 /rhautoimport | |
parent | 4c6858a1213d0b967aa767f6aca72e37b79cee8d (diff) |
use flock to lock multiple calls of the same importer, added sample cron config
Diffstat (limited to 'rhautoimport')
-rwxr-xr-x | rhautoimport | 40 |
1 files changed, 22 insertions, 18 deletions
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 |