3 export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
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}
12 DATE=`date +%Y-%m-%d-%T`
13 MONITOR_PID="${MONITOR_SCRIPT_ROOT}/SKIP"
15 echo "#######################################"; echo "Running Monitor at $DATE"; echo "######################################"
16 echo "Performing API test"
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`
24 if [ -f $MONITOR_PID ] ; then
26 echo "KILLING Monitor"
27 PID=`cat $MONITOR_PID`
30 ${MONITOR_SCRIPT_ROOT}/kill.cmd.sh $PID
33 echo "No PID to be killed."
37 echo "SKIPPING Monitor"
41 echo $$ > $MONITOR_PID
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
52 AGENT=`ps ax | grep ssh-agent | grep -v grep`
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/debug_ssh_key.rsa
60 ssh-add /etc/planetlab/root_ssh_key.rsa
62 #TODO: should add a call to ssh-add -l to check if the keys are loaded or not.
63 source ${MONITOR_SCRIPT_ROOT}/agent.sh
65 ${MONITOR_SCRIPT_ROOT}/checksync.py $DATE || :
66 ${MONITOR_SCRIPT_ROOT}/syncwithplc.py $DATE || :
67 service plc restart monitor
69 echo "Performing FindAll Nodes"
70 #########################
72 ${MONITOR_SCRIPT_ROOT}/findall.py $DATE || :
73 ps ax | grep BatchMode | grep -v grep | awk '{print $1}' | xargs -r kill || :
74 # clean up stray 'locfg' processes that hang around inappropriately...
75 ps ax | grep locfg | grep -v grep | awk '{print $1}' | xargs -r kill || :
77 ${MONITOR_SCRIPT_ROOT}/policy.py $DATE
78 ${MONITOR_SCRIPT_ROOT}/checksync.py $DATE || :
79 service plc restart monitor
80 curl -s 'http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeview&formatcsv' > /var/lib/monitor/comon/$DATE.comon.csv
82 cp ${MONITOR_SCRIPT_ROOT}/monitor.log ${MONITOR_ARCHIVE_ROOT}/`date +%F-%H:%M`.monitor.log