-PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-ovs_vswitchd=/usr/sbin/ovs-vswitchd
-ovsdb_server=/usr/bin/ovsdb-server
-
-(test -x $ovsdb_server && test -x $ovs_vswitchd) || exit 0
-
-DODTIME=1 # Time to wait for the server to die, in seconds
- # If this value is set too low you might not
- # let some servers to die gracefully and
- # 'restart' will not work
-
-# Include ovs-openflowd defaults if available
-unset OVSDB_SERVER_OPTS
-unset OVS_VSWITCHD_OPTS
-unset CORE_LIMIT
-default=/etc/default/openvswitch-switch
-if [ -f $default ] ; then
- . $default
-fi
-
-set -e
-
-# running_pid pid name
-#
-# Check if 'pid' is a process named 'name'
-running_pid()
-{
- local pid=$1 name=$2
- [ -z "$pid" ] && return 1
- [ ! -d /proc/$pid ] && return 1
- cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
- # Is this the expected child?
- case $cmd in
- $name|*/$name)
- return 0
- ;;
- *)
- return 1
- ;;
- esac
-}
-
-# running name
-#
-# Checks for a running process named 'name' by looking for a pidfile
-# named /var/run/${name}.pid
-running()
-{
- local name=$1
- local pidfile=/var/run/${name}.pid
-
- # No pidfile, probably no daemon present
- [ ! -f "$pidfile" ] && return 1
-
- # Obtain the pid and check it against the binary name
- pid=`cat $pidfile`
- running_pid $pid $name || return 1
- return 0
-}
-
-# force_stop name
-#
-# Checks for a running process named 'name', by looking for a pidfile
-# named /var/run/${name}.pid, and then kills it and waits for it to
-# die.
-force_stop() {
- local name=$1
- local pidfile=/var/run/${name}.pid
-
- [ ! -f "$pidfile" ] && return
- if running $name; then
- kill $pid
- [ -n "$DODTIME" ] && sleep "$DODTIME"s
- if running $name; then
- kill -KILL $pid
- [ -n "$DODTIME" ] && sleep "$DODTIME"s
- if running $name; then
- echo "Cannot kill $name (pid=$pid)!"
- exit 1
- fi
- fi
- fi
- rm -f $pidfile
- return 0
-}
-
-must_succeed() {
- echo -n "$1: "
- shift
- if "$@"; then
- echo "success."
- else
- echo " ERROR."
- exit 1
- fi
-}
-
-check_op() {
- echo -n "$1: "
- shift
- if "$@"; then
- echo "success."
- else
- echo " ERROR."
- fi
-}