#!/bin/sh # Copyright (C) 2008, 2009 Nicira Networks, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin OPENFLOWD_PID=/var/run/ovs-openflowd.pid OPENFLOWD_SOCK=/var/run/ovs-openflowd.mgmt LOG_FILE=/var/log/openflow/monitor INTERVAL=1 FAIL_THRESH=3 usage() { echo usage: $0 options echo echo "OPTIONS:" echo " -h Show this message" echo " -p PID file for ovs-openflowd (default: $OPENFLOWD_PID)" echo " -s Unix socket for ovs-openflowd (default: $OPENFLOWD_SOCK)" echo " -l File to log messages (default: $LOG_FILE)" echo " -i Interval to send probes in seconds (default: $INTERVAL)" echo " -c Number of failed probes before reboot (default: $FAIL_THRESH)" } log() { echo `date +"%b %d %X"`:$1 echo `date +"%b %d %X"`:$1 >> $LOG_FILE } while getopts "hp:s:l:i:c:" OPTION; do case $OPTION in h) usage exit 1 ;; p) OPENFLOWD_PID=$OPTARG ;; s) OPENFLOWD_SOCK=$OPTARG ;; l) LOG_FILE=$OPTARG ;; i) INTERVAL=$OPTARG ;; c) FAIL_THRESH=$OPTARG ;; *) echo "Unknown option: ${OPTION}" esac done if [ ! -f $OPENFLOWD_PID ]; then log "No ovs-openflowd pid file: ${OPENFLOWD_PID}" echo "No ovs-openflowd pid file: ${OPENFLOWD_PID}" fi if [ ! -S $OPENFLOWD_SOCK ]; then log "No ovs-openflowd sock file: ${OPENFLOWD_SOCK}" echo "No ovs-openflowd sock file: ${OPENFLOWD_SOCK}" fi if [ ! -d `dirname $LOG_FILE` ]; then mkdir -p `dirname $LOG_FILE` fi let DP_DOWN=0 let OPENFLOWD_DOWN=0 log "===== Starting Monitor ====" while `/bin/true`; do # Only check for liveness if ovs-openflowd's PID file exists. The PID # file is removed when ovs-openflowd is brought down gracefully. if [ -f $OPENFLOWD_PID ]; then pid=`cat $OPENFLOWD_PID` if [ -d /proc/$pid ]; then # Check if the ovs-openflowd and datapath still can communicate if [ -S $OPENFLOWD_SOCK ]; then ovs-ofctl probe -t 2 unix:$OPENFLOWD_SOCK if [ $? -ne 0 ]; then log "datapath probe failed" let DP_DOWN++ else let DP_DOWN=0 fi fi let OPENFLOWD_DOWN=0 else log "ovs-openflowd probe failed" let OPENFLOWD_DOWN++ fi fi if [ $OPENFLOWD_DOWN -ge $FAIL_THRESH ]; then log "Failed to probe ovs-openflowd after ${OPENFLOWD_DOWN} tries...rebooting!" reboot fi if [ $DP_DOWN -ge $FAIL_THRESH ]; then log "Failed to probe datapath after ${DP_DOWN} tries...rebooting!" reboot fi sleep $INTERVAL done