https://www.mediawiki.org/wiki/Special:Code/MediaWiki/109616

Revision: 109616
Author:   ariel
Date:     2012-01-20 13:47:57 +0000 (Fri, 20 Jan 2012)
Log Message:
-----------
make failout actually check fails in a row, not total; logging option; standard 
syntax for options now

Modified Paths:
--------------
    branches/ariel/xmldumps-backup/worker

Modified: branches/ariel/xmldumps-backup/worker
===================================================================
--- branches/ariel/xmldumps-backup/worker       2012-01-20 13:44:13 UTC (rev 
109615)
+++ branches/ariel/xmldumps-backup/worker       2012-01-20 13:47:57 UTC (rev 
109616)
@@ -1,32 +1,60 @@
 #!/bin/bash
 
-# number of failures of worker.py in a row before we decide
+# default number of failures of worker.py in a row before we decide
 # something serious is broken and we refuse to run
 MAXFAILS=3
+# default: don't pass special config file
+CONFIGFILE=""
+# default: no logging to file
+LOG=""
+
 failures=0
-
 WIKIDUMP_BASE=`dirname "$0"`
 
-if [ ! -z "$1" ]; then
-    configFile="$1"
+while [ $# -gt 0 ]; do
+    if [ $1 == "--configfile" ]; then
+       CONFIGFILE="$2"
+       shift; shift
+    elif [ $1 == "--maxfails" ]; then
+       MAXFAILS="$2"
+       shift; shift
+    elif [ $1 == "--log" ]; then
+       LOG=true
+       shift;
+    else
+       echo "$0: Unknown option $1"
+       echo "Usage: $0 [--configfile filename] [--log] [--maxfails num]"
+       echo "--configfile   use specified file for config file (default: 
wikidump.conf)"
+       echo "--log          write log of (almost) everything written to stderr 
(default: no logging)"
+       echo "--maxfails     if more than this many dumps fail in a row, exit 
(default: 3)"
+       exit 1
+    fi
+done
+
+# set up the command
+pythonargs=( "$WIKIDUMP_BASE/worker.py" )
+if [ ! -z "$CONFIGFILE" ]; then
+    pythonargs=( "${pythonargs[@]}" "--configfile" "$CONFIGFILE" )
 fi
+if [ ! -z "$LOG" ]; then
+    pythonargs=( "${pythonargs[@]}" "--log" )
+fi
 
 while true; do
     if [ -e "$WIKIDUMP_BASE/maintenance.txt" ]; then
        echo "in maintenance mode, sleeping 5 minutes"
        sleep 300
     else
-       if [ ! -z "$configFile" ]; then
-           python $WIKIDUMP_BASE/worker.py "--configfile" "$configFile"
-       else
-           python $WIKIDUMP_BASE/worker.py
-       fi
+       echo python ${pythonargs[@]}
+       python ${pythonargs[@]}
        if [ $? -ne 0 ]; then
            failures=$(($failures+1))
            if [ $failures -gt $MAXFAILS ]; then
                echo "more than $MAXFAILS failures in a row, halting."
                exit 1
            fi
+       else
+           failures=0
        fi
        echo "sleeping"
        sleep 30


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to