2009-07-08 13:19:16 -07:00
|
|
|
#! /bin/sh
|
|
|
|
#
|
|
|
|
# /etc/init.d/openvswitch-switch
|
|
|
|
#
|
|
|
|
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
|
|
|
|
# Modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>.
|
|
|
|
# Further changes by Javier Fernandez-Sanguino <jfs@debian.org>
|
|
|
|
# Modified for openvswitch-switch.
|
|
|
|
#
|
|
|
|
# Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl
|
|
|
|
#
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: openvswitch-switch
|
|
|
|
# Required-Start: $network $named $remote_fs $syslog
|
|
|
|
# Required-Stop:
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Short-Description: Open vSwitch switch
|
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
2009-12-15 13:11:24 -08:00
|
|
|
ovs_vswitchd=/usr/sbin/ovs-vswitchd
|
|
|
|
ovsdb_server=/usr/bin/ovsdb-server
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2009-12-15 13:11:24 -08:00
|
|
|
(test -x $ovsdb_server && test -x $ovs_vswitchd) || exit 0
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2009-07-08 10:30:42 -07:00
|
|
|
# Include ovs-openflowd defaults if available
|
2009-12-15 13:11:24 -08:00
|
|
|
unset OVSDB_SERVER_OPTS
|
|
|
|
unset OVS_VSWITCHD_OPTS
|
2009-07-08 13:19:16 -07:00
|
|
|
unset CORE_LIMIT
|
|
|
|
default=/etc/default/openvswitch-switch
|
|
|
|
if [ -f $default ] ; then
|
2010-01-11 15:31:14 -08:00
|
|
|
. $default
|
2009-07-08 13:19:16 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2009-12-15 13:11:24 -08:00
|
|
|
# running_pid pid name
|
|
|
|
#
|
|
|
|
# Check if 'pid' is a process named 'name'
|
2009-07-08 13:19:16 -07:00
|
|
|
running_pid()
|
|
|
|
{
|
2009-12-15 13:11:24 -08:00
|
|
|
local pid=$1 name=$2
|
2009-07-08 13:19:16 -07:00
|
|
|
[ -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
|
|
|
|
}
|
|
|
|
|
2009-12-15 13:11:24 -08:00
|
|
|
# running name
|
|
|
|
#
|
|
|
|
# Checks for a running process named 'name' by looking for a pidfile
|
|
|
|
# named /var/run/${name}.pid
|
2009-07-08 13:19:16 -07:00
|
|
|
running()
|
|
|
|
{
|
2009-12-15 13:11:24 -08:00
|
|
|
local name=$1
|
|
|
|
local pidfile=/var/run/${name}.pid
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
# No pidfile, probably no daemon present
|
2009-12-15 13:11:24 -08:00
|
|
|
[ ! -f "$pidfile" ] && return 1
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
# Obtain the pid and check it against the binary name
|
2009-12-15 13:11:24 -08:00
|
|
|
pid=`cat $pidfile`
|
|
|
|
running_pid $pid $name || return 1
|
2009-07-08 13:19:16 -07:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2009-12-15 13:11:24 -08:00
|
|
|
# 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.
|
2009-07-08 13:19:16 -07:00
|
|
|
force_stop() {
|
2009-12-15 13:11:24 -08:00
|
|
|
local name=$1
|
|
|
|
local pidfile=/var/run/${name}.pid
|
|
|
|
|
|
|
|
[ ! -f "$pidfile" ] && return
|
|
|
|
if running $name; then
|
|
|
|
kill $pid
|
2009-07-08 13:19:16 -07:00
|
|
|
[ -n "$DODTIME" ] && sleep "$DODTIME"s
|
2009-12-15 13:11:24 -08:00
|
|
|
if running $name; then
|
|
|
|
kill -KILL $pid
|
2009-07-08 13:19:16 -07:00
|
|
|
[ -n "$DODTIME" ] && sleep "$DODTIME"s
|
2009-12-15 13:11:24 -08:00
|
|
|
if running $name; then
|
|
|
|
echo "Cannot kill $name (pid=$pid)!"
|
2009-07-08 13:19:16 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2009-12-15 13:11:24 -08:00
|
|
|
rm -f $pidfile
|
2009-07-08 13:19:16 -07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2009-12-15 13:11:24 -08:00
|
|
|
# is_module_loaded module
|
|
|
|
#
|
|
|
|
# Returns 0 if 'module' is loaded, 1 otherwise.
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2009-12-15 13:11:24 -08:00
|
|
|
is_module_loaded() {
|
|
|
|
local module=$1
|
|
|
|
grep -q "^$module " /proc/modules
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
|
2009-12-15 13:11:24 -08:00
|
|
|
# load_module module
|
|
|
|
#
|
|
|
|
# Loads 'module' into the running kernel, if it is not already loaded.
|
|
|
|
load_module() {
|
|
|
|
local module=$1
|
|
|
|
echo -n "Loading $module: "
|
|
|
|
if is_module_loaded $module; then
|
|
|
|
echo "already loaded, nothing to do."
|
|
|
|
elif modprobe $module; then
|
|
|
|
echo "success."
|
|
|
|
else
|
|
|
|
echo "ERROR."
|
|
|
|
echo "$module has probably not been built for this kernel."
|
|
|
|
if ! test -d /usr/share/doc/openvswitch-datapath-source; then
|
|
|
|
echo "Install the openvswitch-datapath-source package, then read"
|
|
|
|
echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
|
2009-07-08 13:19:16 -07:00
|
|
|
else
|
2009-12-15 13:11:24 -08:00
|
|
|
echo "For instructions, read"
|
|
|
|
echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
|
2009-07-08 13:19:16 -07:00
|
|
|
fi
|
2009-12-15 13:11:24 -08:00
|
|
|
exit 1
|
2009-07-08 13:19:16 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-12-15 13:11:24 -08:00
|
|
|
# unload_module module
|
|
|
|
#
|
|
|
|
# Unloads 'module' from the running kernel, if it is loaded.
|
|
|
|
unload_module() {
|
|
|
|
local module=$1
|
|
|
|
echo -n "Unloading $module: "
|
|
|
|
if is_module_loaded $module; then
|
|
|
|
if rmmod $module; then
|
2009-07-08 13:19:16 -07:00
|
|
|
echo "success."
|
|
|
|
else
|
|
|
|
echo "ERROR."
|
|
|
|
exit 1
|
|
|
|
fi
|
2009-12-15 13:11:24 -08:00
|
|
|
else
|
|
|
|
echo "not loaded, nothing to do."
|
|
|
|
fi
|
|
|
|
}
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2009-12-15 13:11:24 -08:00
|
|
|
unload_modules() {
|
|
|
|
if is_module_loaded openvswitch_mod; then
|
|
|
|
for dp in $(ovs-dpctl dump-dps); do
|
|
|
|
echo -n "Deleting datapath $dp: "
|
|
|
|
if ovs-dpctl del-dp $dp; then
|
|
|
|
echo "success."
|
2009-07-08 13:19:16 -07:00
|
|
|
else
|
2009-12-15 13:11:24 -08:00
|
|
|
echo "ERROR."
|
2009-07-08 13:19:16 -07:00
|
|
|
fi
|
2009-12-15 13:11:24 -08:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
unload_module openvswitch_mod
|
|
|
|
unload_module ip_gre_mod
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
load_module openvswitch_mod
|
|
|
|
unload_module ip_gre
|
|
|
|
load_module ip_gre_mod
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
if test -n "$CORE_LIMIT"; then
|
|
|
|
check_op "Setting core limit to $CORE_LIMIT" ulimit -c "$CORE_LIMIT"
|
|
|
|
fi
|
|
|
|
|
2010-01-11 15:20:44 -08:00
|
|
|
# Create an empty configuration database if it doesn't exist.
|
|
|
|
if test ! -e /etc/openvswitch-switch/conf; then
|
|
|
|
# Create configuration database.
|
|
|
|
ovsdb-tool -vANY:console:emer \
|
|
|
|
create /etc/openvswitch-switch/conf \
|
|
|
|
/usr/share/openvswitch/vswitch-idl.ovsschema
|
|
|
|
fi
|
|
|
|
|
2009-12-15 13:11:24 -08:00
|
|
|
# Start ovsdb-server.
|
2009-07-08 13:19:16 -07:00
|
|
|
set --
|
|
|
|
set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
|
|
|
|
set -- "$@" --log-file
|
2009-12-15 13:11:24 -08:00
|
|
|
set -- "$@" --detach --pidfile
|
2010-01-04 10:05:51 -08:00
|
|
|
set -- "$@" --remote punix:/var/run/ovsdb-server
|
2009-12-15 13:11:24 -08:00
|
|
|
set -- "$@" /etc/openvswitch-switch/conf
|
|
|
|
set -- "$@" $OVSDB_SERVER_OPTS
|
2010-01-11 15:31:14 -08:00
|
|
|
echo -n "Starting ovsdb-server: "
|
|
|
|
start-stop-daemon --start --quiet --pidfile /var/run/ovsdb-server.pid \
|
|
|
|
--exec $ovsdb_server -- "$@"
|
2009-12-15 13:11:24 -08:00
|
|
|
if running ovsdb-server; then
|
|
|
|
echo "ovsdb-server."
|
2009-07-08 13:19:16 -07:00
|
|
|
else
|
|
|
|
echo " ERROR."
|
|
|
|
fi
|
|
|
|
|
2010-01-11 15:20:44 -08:00
|
|
|
ovs-vsctl --no-wait init
|
|
|
|
|
2009-12-15 13:11:24 -08:00
|
|
|
# Start ovs-vswitchd.
|
|
|
|
set --
|
|
|
|
set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
|
|
|
|
set -- "$@" --log-file
|
|
|
|
set -- "$@" --detach --pidfile
|
|
|
|
set -- "$@" unix:/var/run/ovsdb-server
|
|
|
|
set -- "$@" $OVS_VSWITCHD_OPTS
|
2010-01-11 15:31:14 -08:00
|
|
|
echo -n "Starting ovs-vswitchd: "
|
|
|
|
start-stop-daemon --start --quiet --pidfile /var/run/ovs-vswitchd.pid \
|
|
|
|
--exec $ovs_vswitchd -- "$@"
|
2009-12-15 13:11:24 -08:00
|
|
|
if running ovs-vswitchd; then
|
|
|
|
echo "ovs-vswitchd."
|
|
|
|
else
|
|
|
|
echo " ERROR."
|
2009-07-08 13:19:16 -07:00
|
|
|
fi
|
2010-01-11 15:31:14 -08:00
|
|
|
;;
|
2009-07-08 13:19:16 -07:00
|
|
|
stop)
|
2010-01-11 15:31:14 -08:00
|
|
|
echo -n "Stopping ovs-vswitchd: "
|
|
|
|
start-stop-daemon --stop --quiet --oknodo \
|
2009-12-15 13:11:24 -08:00
|
|
|
--pidfile /var/run/ovs-vswitchd.pid \
|
|
|
|
--exec $ovs_vswitchd
|
2010-01-11 15:31:14 -08:00
|
|
|
echo "ovs-vswitchd."
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2010-01-11 15:31:14 -08:00
|
|
|
echo -n "Stopping ovsdb-server: "
|
|
|
|
start-stop-daemon --stop --quiet --oknodo \
|
2009-12-15 13:11:24 -08:00
|
|
|
--pidfile /var/run/ovsdb-server.pid \
|
|
|
|
--exec $ovsdb_server
|
2010-01-11 15:31:14 -08:00
|
|
|
echo "ovsdb-server."
|
|
|
|
;;
|
2009-07-08 13:19:16 -07:00
|
|
|
force-stop)
|
2010-01-11 15:31:14 -08:00
|
|
|
echo -n "Forcefully stopping ovs-vswitchd: "
|
2009-12-15 13:11:24 -08:00
|
|
|
force_stop ovs-vswitchd
|
|
|
|
if ! running ovs-vswitchd; then
|
|
|
|
echo "ovs-vswitchd."
|
2009-07-08 13:19:16 -07:00
|
|
|
else
|
|
|
|
echo " ERROR."
|
|
|
|
fi
|
2009-12-15 13:11:24 -08:00
|
|
|
|
2010-01-11 15:31:14 -08:00
|
|
|
echo -n "Forcefully stopping ovsdb-server: "
|
2009-12-15 13:11:24 -08:00
|
|
|
force_stop ovsdb-server
|
|
|
|
if ! running ovsdb-server; then
|
|
|
|
echo "ovsdb-server."
|
|
|
|
else
|
|
|
|
echo " ERROR."
|
|
|
|
fi
|
2010-01-11 15:31:14 -08:00
|
|
|
;;
|
2009-12-16 13:40:55 -08:00
|
|
|
unload)
|
2010-01-11 15:31:14 -08:00
|
|
|
unload_modules
|
|
|
|
;;
|
2009-07-08 13:19:16 -07:00
|
|
|
reload)
|
|
|
|
;;
|
|
|
|
force-reload)
|
2009-12-15 13:11:24 -08:00
|
|
|
# Nothing to do, since ovs-vswitchd automatically reloads
|
|
|
|
# whenever its configuration changes, and ovsdb-server doesn't
|
|
|
|
# have anything to reload.
|
2010-01-11 15:31:14 -08:00
|
|
|
;;
|
2009-07-08 13:19:16 -07:00
|
|
|
restart)
|
|
|
|
$0 stop || true
|
|
|
|
$0 start
|
2010-01-11 15:31:14 -08:00
|
|
|
;;
|
2009-07-08 13:19:16 -07:00
|
|
|
status)
|
2009-12-15 13:11:24 -08:00
|
|
|
for daemon in ovs-vswitchd ovsdb-server; do
|
|
|
|
echo -n "$daemon is "
|
|
|
|
if running $daemon; then
|
|
|
|
echo "running"
|
|
|
|
else
|
|
|
|
echo " not running."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2009-07-08 13:19:16 -07:00
|
|
|
;;
|
|
|
|
*)
|
2010-01-11 15:31:14 -08:00
|
|
|
N=/etc/init.d/$NAME
|
|
|
|
echo "Usage: $N {start|stop|restart|force-reload|status|force-stop|unload}" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
2009-07-08 13:19:16 -07:00
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|