3 # Copyright (C) 2008, 2009 Nicira Networks, Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
19 OPENFLOWD_PID=/var/run/openvswitch/ovs-openflowd.pid
20 OPENFLOWD_SOCK=/var/run/openvswitch/ovs-openflowd.mgmt
21 LOG_FILE=/var/log/openvswitch/ovs-monitor.log
26 echo usage: $0 options
29 echo " -h Show this message"
30 echo " -p PID file for ovs-openflowd (default: $OPENFLOWD_PID)"
31 echo " -s Unix socket for ovs-openflowd (default: $OPENFLOWD_SOCK)"
32 echo " -l File to log messages (default: $LOG_FILE)"
33 echo " -i Interval to send probes in seconds (default: $INTERVAL)"
34 echo " -c Number of failed probes before reboot (default: $FAIL_THRESH)"
38 echo `date +"%b %d %X"`:$1
39 echo `date +"%b %d %X"`:$1 >> $LOG_FILE
43 while getopts "hp:s:l:i:c:" OPTION; do
55 OPENFLOWD_SOCK=$OPTARG
71 echo "Unknown option: ${OPTION}"
76 if [ ! -f $OPENFLOWD_PID ]; then
77 log "No ovs-openflowd pid file: ${OPENFLOWD_PID}"
78 echo "No ovs-openflowd pid file: ${OPENFLOWD_PID}"
81 if [ ! -S $OPENFLOWD_SOCK ]; then
82 log "No ovs-openflowd sock file: ${OPENFLOWD_SOCK}"
83 echo "No ovs-openflowd sock file: ${OPENFLOWD_SOCK}"
86 if [ ! -d `dirname $LOG_FILE` ]; then
87 mkdir -p `dirname $LOG_FILE`
92 log "===== Starting Monitor ===="
94 # Only check for liveness if ovs-openflowd's PID file exists. The PID
95 # file is removed when ovs-openflowd is brought down gracefully.
96 if [ -f $OPENFLOWD_PID ]; then
97 pid=`cat $OPENFLOWD_PID`
98 if [ -d /proc/$pid ]; then
99 # Check if the ovs-openflowd and datapath still can communicate
100 if [ -S $OPENFLOWD_SOCK ]; then
101 ovs-ofctl probe -t 2 unix:$OPENFLOWD_SOCK
102 if [ $? -ne 0 ]; then
103 log "datapath probe failed"
111 log "ovs-openflowd probe failed"
116 if [ $OPENFLOWD_DOWN -ge $FAIL_THRESH ]; then
117 log "Failed to probe ovs-openflowd after ${OPENFLOWD_DOWN} tries...rebooting!"
121 if [ $DP_DOWN -ge $FAIL_THRESH ]; then
122 log "Failed to probe datapath after ${DP_DOWN} tries...rebooting!"