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 $INSTALLPATH/commands/shconfig.py > $INSTALLPATH/monitorconfig.sh
8 source $INSTALLPATH/monitorconfig.sh
9 cd ${MONITOR_SCRIPT_ROOT}
11 DATE=`date +%Y-%m-%d-%T`
12 MONITOR_PID="${MONITOR_SCRIPT_ROOT}/SKIP"
14 echo "#######################################"; echo "Running Monitor at $DATE"; echo "######################################"
15 echo "Performing API test"
16 API=$(${MONITOR_SCRIPT_ROOT}/tools/testapi.py)
17 if [ "$API" != "ok" ] ; then
18 # NOTE: Do not try to run any commands if the API is obviously broken.
19 echo "API IS DOWN : "`date`
23 if [ -f $MONITOR_PID ] ; then
25 echo "KILLING Monitor"
26 PID=`cat $MONITOR_PID`
29 ${MONITOR_SCRIPT_ROOT}/tools/kill.cmd.sh $PID
32 echo "No PID to be killed."
36 echo "SKIPPING Monitor"
40 echo $$ > $MONITOR_PID
42 # SETUP act_all database if it's not there.
43 if [ ! -f ${MONITOR_SCRIPT_ROOT}/actallsetup.flag ]; then
44 if ! python -c 'import database; database.dbLoad("act_all")' 2>/dev/null ; then
45 touch ${MONITOR_SCRIPT_ROOT}/actallsetup.flag
51 AGENT=`ps ax | grep ssh-agent | grep -v grep`
53 if [ -z "$AGENT" ] ; then
54 echo "starting ssh agent"
55 # if no agent is running, set it up.
56 ssh-agent > ${MONITOR_SCRIPT_ROOT}/agent.sh
57 source ${MONITOR_SCRIPT_ROOT}/agent.sh
58 ssh-add /etc/planetlab/myops_ssh_key.rsa
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}/commands/syncwithplc.py $DATE || :
66 service plc restart monitor
68 echo "Performing FindAll Nodes"
69 #########################
71 ${MONITOR_SCRIPT_ROOT}/commands/findall.py $DATE || :
72 ps ax | grep BatchMode | grep -v grep | awk '{print $1}' | xargs -r kill || :
73 # clean up stray 'locfg' processes that hang around inappropriately...
74 ps ax | grep locfg | grep -v grep | awk '{print $1}' | xargs -r kill || :
77 ${MONITOR_SCRIPT_ROOT}/commands/policy.py $DATE || :
78 curl -s 'http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeview&formatcsv' > /var/lib/monitor/comon/$DATE.comon.csv || :
80 cp ${MONITOR_SCRIPT_ROOT}/monitor.log ${MONITOR_ARCHIVE_ROOT}/`date +%F-%H:%M`.monitor.log
81 service plc restart monitor || :