- fix UP/DOWN summary on nodes page.
[monitor.git] / automate-default.sh
1 #!/bin/bash
2
3 export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
4
5 # NOTE: Must be an absolute path to guarantee it is read.
6 INSTALLPATH=/usr/share/monitor/
7 # Generate an 'sh' style file full of variables in monitor.conf
8 $INSTALLPATH/shconfig.py >  $INSTALLPATH/monitorconfig.sh
9 source $INSTALLPATH/monitorconfig.sh
10 cd ${MONITOR_SCRIPT_ROOT}
11 set -e
12 DATE=`date +%Y-%m-%d-%T`
13 MONITOR_PID="${MONITOR_SCRIPT_ROOT}/SKIP"
14
15 echo "#######################################"; echo "Running Monitor at $DATE"; echo "######################################"
16 echo "Performing API test"
17 API=$(./testapi.py)
18 if [ "$API" != "ok" ] ; then 
19         # NOTE: Do not try to run any commands if the API is obviously broken.
20         echo "API IS DOWN : "`date`
21         exit 1
22 fi
23
24 if [ -f $MONITOR_PID ] ; then 
25         if [ -z "$1" ] ; then 
26                 echo "KILLING Monitor"
27                 PID=`cat $MONITOR_PID`
28                 rm -f $MONITOR_PID
29                 if [ -z $PID ] ; then
30                         ${MONITOR_SCRIPT_ROOT}/kill.cmd.sh $PID
31                         echo "done."
32                 else
33                         echo "No PID to be killed."
34                 fi
35         else 
36                 # skipping monitor
37                 echo "SKIPPING Monitor"
38                 exit
39         fi 
40 fi
41 echo $$ > $MONITOR_PID
42
43 # SETUP act_all database if it's not there.
44 if [ ! -f ${MONITOR_SCRIPT_ROOT}/actallsetup.flag ]; then
45         if ! python -c 'import database; database.dbLoad("act_all")' 2>/dev/null ; then 
46                 touch ${MONITOR_SCRIPT_ROOT}/actallsetup.flag
47         fi
48 fi
49
50
51 set +e
52 AGENT=`ps ax | grep ssh-agent | grep -v grep`
53 set -e
54 if [ -z "$AGENT" ] ; then
55         echo "starting ssh agent"
56         # if no agent is running, set it up.
57         ssh-agent > ${MONITOR_SCRIPT_ROOT}/agent.sh
58         source ${MONITOR_SCRIPT_ROOT}/agent.sh
59         ssh-add /etc/planetlab/myops_ssh_key.rsa
60         ssh-add /etc/planetlab/debug_ssh_key.rsa
61         ssh-add /etc/planetlab/root_ssh_key.rsa
62 fi
63 #TODO: should add a call to ssh-add -l to check if the keys are loaded or not.
64 source ${MONITOR_SCRIPT_ROOT}/agent.sh
65
66 #${MONITOR_SCRIPT_ROOT}/checksync.py $DATE || :
67 ${MONITOR_SCRIPT_ROOT}/syncwithplc.py $DATE || :
68 service plc restart monitor
69
70 echo "Performing FindAll Nodes"
71 #########################
72 # 1. FINDBAD NODES 
73 ${MONITOR_SCRIPT_ROOT}/findall.py $DATE || :
74 ps ax | grep BatchMode | grep -v grep | awk '{print $1}' | xargs -r kill || :
75 # clean up stray 'locfg' processes that hang around inappropriately...
76 ps ax | grep locfg | grep -v grep | awk '{print $1}' | xargs -r kill || :
77
78
79 ${MONITOR_SCRIPT_ROOT}/policy.py $DATE || :
80 ${MONITOR_SCRIPT_ROOT}/statistics/add-record.py || :
81 curl -s 'http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeview&formatcsv' > /var/lib/monitor/comon/$DATE.comon.csv || :
82
83 cp ${MONITOR_SCRIPT_ROOT}/monitor.log ${MONITOR_ARCHIVE_ROOT}/`date +%F-%H:%M`.monitor.log
84 service plc restart monitor || :
85 rm -f $MONITOR_PID