summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-03-13 04:22:06 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-03-13 04:22:06 (GMT)
commit33fd3033edccb73143223855f6f6f6305102d9d4 (patch)
treefac00827e5a28fd3b8bb2e64e9f4b1db3498393b
parent4c6858a1213d0b967aa767f6aca72e37b79cee8d (diff)
use flock to lock multiple calls of the same importer, added sample cron config
-rw-r--r--cron7
-rw-r--r--depends1
-rwxr-xr-xrhautoimport40
3 files changed, 30 insertions, 18 deletions
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
+#
+##############
+# <show title>
+27 18,19,20 * * 1-5 autoimport /usr/bin/rhautoimport-<code>
+27 21 * * 1-5 autoimport /usr/bin/rhautoimport-<code> 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