Changeset 689

Show
Ignore:
Timestamp:
01/08/2005 12:28:03 PM (4 years ago)
Author:
chris
Message:

eddie_wrapper improvements: eddie output on exit is only emailed to
$EDDIE_ADMIN if the Eddie return-code is non-zero. By default no
$EDDIE_ADMIN is set (so no email is sent by default) and $EDDIE_ADMIN
can now be defined outside the eddie_wrapper script (ie: in a startup
script).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • eddie/trunk/bin/eddie_wrapper

    r668 r689  
    2525######################################################################## 
    2626 
    27 ## Address to receive restart messages.  Set to empty or comment out to 
    28 ##   disable sending messages. 
    29 #EDDIE_ADMIN=eddie-adm@domain.name 
    30 EDDIE_ADMIN=root 
     27## Address to receive restart messages, including tracebacks for any 
     28##   bad exceptions.  Set to empty or comment out to disable sending 
     29##   messages.  If set as an environment variable it will not be 
     30##   over-written.  Defaults to not set. 
     31 
     32if [ $EDDIE_ADMIN = "" ] 
     33then 
     34    #EDDIE_ADMIN=eddie-adm@domain.name 
     35    EDDIE_ADMIN= 
     36fi 
    3137 
    3238## Failure to start EDDIE-Tool after MAX_RETRIES in a short period of time 
     
    4753## Create (if necessary) /var/run/eddie/tmp 
    4854if [ ! -d /var/run/eddie/tmp ]; then 
    49         mkdir -p /var/run/eddie/tmp >/dev/null 2>&1 
    50         if [ $? -gt 0 ]; then 
    51                 echo '$0: "mkdir -p /var/run/eddie/tmp" failed.' 
    52                 RUNFILE=/var/tmp/eddie$$.out 
    53         fi 
     55    mkdir -p /var/run/eddie/tmp >/dev/null 2>&1 
     56    if [ $? -gt 0 ]; then 
     57        echo '$0: "mkdir -p /var/run/eddie/tmp" failed.' 
     58        RUNFILE=/var/tmp/eddie$$.out 
     59    fi 
    5460fi 
    5561 
    5662## Find mail program 
    5763if [ -x /bin/mailx ]; then              # Solaris 
    58         MAIL=/bin/mailx 
     64    MAIL=/bin/mailx 
    5965elif [ -x /bin/mail ]; then             # Linux 
    60         MAIL=/bin/mail 
     66    MAIL=/bin/mail 
    6167else 
    62         MAIL=mail                               # dunno... 
     68    MAIL=mail                           # dunno... 
    6369fi 
    6470 
     
    7076if [ "$PGREP" = "" ] 
    7177then 
    72         PGREP="useps" 
     78    PGREP="useps" 
    7379fi 
    7480 
     
    7783if [ "$EDDIEPATH" = "" ] 
    7884then 
    79         EDDIEPATH="." 
     85    EDDIEPATH="." 
    8086fi 
    8187 
     
    8692 
    8793while [ 1 ]; do 
    88         if [ "$PGREP" = "useps" ] 
    89         then 
    90             pid=`ps -ef | grep \.\*python\.\*eddie.py  | grep -v grep | awk '{ print $2 }'` 
    91         else 
    92             pid=`$PGREP eddie.py` 
    93         fi 
     94    if [ "$PGREP" = "useps" ] 
     95    then 
     96        pid=`ps -ef | grep \.\*python\.\*eddie.py  | grep -v grep | awk '{ print $2 }'` 
     97    else 
     98        pid=`$PGREP eddie.py` 
     99    fi 
    94100 
    95         if [ "${pid}" != "" ]; then 
    96                 echo "Error: Eddie is already running." 
    97                 exit 2 
    98         fi 
     101    if [ "${pid}" != "" ]; then 
     102        echo "Error: Eddie is already running." 
     103        exit 2 
     104    fi 
    99105 
    100         #start_time=`$GDATE "+%s"` 
    101         start_time=`$PYTHON -c "import time ; print int(time.time())"` 
     106    #start_time=`$GDATE "+%s"` 
     107    start_time=`$PYTHON -c "import time ; print int(time.time())"` 
    102108 
    103         $EDDIEPATH/eddie.py >>$RUNFILE 
     109    $EDDIEPATH/eddie.py >>$RUNFILE 
    104110 
    105         retcode=$? 
     111    retcode=$? 
     112 
     113    if [ $retcode -ne 0 ] 
     114    then 
    106115        echo "eddie_wrapper: eddie died at `date` return code: $retcode" >> $RUNFILE 
    107116 
     
    109118        restart_time=`expr $curtime - $start_time` 
    110119        if [ $restart_time -lt 120 ]; then 
    111                 tries=`expr $tries + 1` 
     120            tries=`expr $tries + 1` 
    112121        else 
    113                 tries=0 
     122            tries=0 
    114123        fi 
    115124 
    116125        if [ $tries -gt $MAX_TRIES ]; then 
    117                 echo "eddie_wrapper: Too many restarts ($tries) in a short time. eddie_wrapper quitting." >>$RUNFILE 
    118  
    119                 if [ "$EDDIE_ADMIN" != "" ] 
    120                 then 
    121                         $MAIL -s "Eddie output on `hostname` at `date`" $EDDIE_ADMIN < $RUNFILE 
    122                 fi 
    123                 rm $RUNFILE 
    124                 exit 3 
     126            echo "eddie_wrapper: Too many restarts ($tries) in a short time. eddie_wrapper quitting." >>$RUNFILE 
    125127        fi 
    126128 
    127129        if [ "$EDDIE_ADMIN" != "" ] 
    128130        then 
    129                 $MAIL -s "Eddie output on `hostname` at `date`" $EDDIE_ADMIN < $RUNFILE 
     131            # Sent output to EDDIE_ADMIN if defined 
     132            $MAIL -s "Eddie output on `hostname` at `date`" $EDDIE_ADMIN < $RUNFILE 
     133        else 
     134            # Otherwise to stdout 
     135            cat $RUNFILE 
    130136        fi 
    131137        rm -f $RUNFILE 
    132138 
    133         sleep 30 
    134         echo "eddie_wrapper: restarting Eddie at `date` [tries=$tries]." >> $RUNFILE 
     139        if [ $tries -gt $MAX_TRIES ]; then 
     140            exit 3 
     141        fi 
     142 
     143        sleep 60 
     144    else 
     145        sleep 5 
     146    fi 
     147 
     148    rm -f $RUNFILE 
     149 
     150    echo "eddie_wrapper: restarting Eddie at `date` [tries=$tries]." >> $RUNFILE 
    135151done 
    136152