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"
18 mail -s "$subject" $exception_email <<EOF
24 echo "#######################################"; echo "Running Monitor at $DATE"; echo "######################################"
25 echo "Performing API test"
26 API=$(${MONITOR_SCRIPT_ROOT}/tools/testapi.py)
27 if [ "$API" != "ok" ] ; then
28 # NOTE: Do not try to run any commands if the API is obviously broken.
29 echo "API IS DOWN : "`date`
33 if [ -f $MONITOR_PID ] ; then
35 echo "KILLING Monitor"
36 PID=`cat $MONITOR_PID`
39 ${MONITOR_SCRIPT_ROOT}/tools/kill.cmd.sh $PID
42 echo "No PID to be killed."
46 echo "SKIPPING Monitor"
50 echo $$ > $MONITOR_PID
52 # SETUP act_all database if it's not there.
53 if [ ! -f ${MONITOR_SCRIPT_ROOT}/actallsetup.flag ]; then
54 if ! python -c 'import database; database.dbLoad("act_all")' 2>/dev/null ; then
55 touch ${MONITOR_SCRIPT_ROOT}/actallsetup.flag
61 AGENT=`ps ax | grep ssh-agent | grep -v grep`
63 if [ -z "$AGENT" ] ; then
64 echo "starting ssh agent"
65 # if no agent is running, set it up.
66 ssh-agent > ${MONITOR_SCRIPT_ROOT}/agent.sh
67 source ${MONITOR_SCRIPT_ROOT}/agent.sh
68 ssh-add /etc/planetlab/myops_ssh_key.rsa
69 ssh-add /etc/planetlab/debug_ssh_key.rsa
70 ssh-add /etc/planetlab/root_ssh_key.rsa
72 #TODO: should add a call to ssh-add -l to check if the keys are loaded or not.
73 source ${MONITOR_SCRIPT_ROOT}/agent.sh
75 # CHECK AGENT IS UP AND RUNNING
76 count=$( ssh-add -l | wc -l )
77 if [ $count -lt 3 ] ; then
78 send_mail "ssh-agent is not up and running." "Add keys before monitoring can continue"
82 ${MONITOR_SCRIPT_ROOT}/commands/syncwithplc.py $DATE || :
83 service plc restart monitor
85 echo "Performing FindAll Nodes"
86 #########################
88 ${MONITOR_SCRIPT_ROOT}/commands/findall.py $DATE || :
89 ps ax | grep BatchMode | grep -v grep | awk '{print $1}' | xargs -r kill || :
90 # clean up stray 'locfg' processes that hang around inappropriately...
91 ps ax | grep locfg | grep -v grep | awk '{print $1}' | xargs -r kill || :
94 ${MONITOR_SCRIPT_ROOT}/commands/policy.py $DATE || :
95 curl -s 'http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeview&formatcsv' > /var/lib/monitor/comon/$DATE.comon.csv || :
97 cp ${MONITOR_SCRIPT_ROOT}/monitor.log ${MONITOR_ARCHIVE_ROOT}/`date +%F-%H:%M`.monitor.log
98 service plc restart monitor || :