3 # /etc/init.d/openvswitch-switch
5 # Written by Miquel van Smoorenburg <miquels@cistron.nl>.
6 # Modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>.
7 # Further changes by Javier Fernandez-Sanguino <jfs@debian.org>
8 # Modified for openvswitch-switch.
10 # Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl
13 # Provides: openvswitch-switch
14 # Required-Start: $network $named $remote_fs $syslog
15 # Required-Stop: $remote_fs
16 # Default-Start: 2 3 4 5
18 # Short-Description: Open vSwitch switch
21 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
22 ovs_vswitchd=/usr/sbin/ovs-vswitchd
23 ovsdb_server=/usr/bin/ovsdb-server
25 (test -x $ovsdb_server && test -x $ovs_vswitchd) || exit 0
27 DODTIME=1 # Time to wait for the server to die, in seconds
28 # If this value is set too low you might not
29 # let some servers to die gracefully and
30 # 'restart' will not work
32 # Include openvswitch-switch defaults if available
33 unset OVSDB_SERVER_OPTS
34 unset OVS_VSWITCHD_OPTS
37 default=/etc/default/openvswitch-switch
38 if [ -f $default ] ; then
42 : ${ENABLE_MONITOR:=y}
46 # running_pid pid name
48 # Check if 'pid' is a process named 'name'
52 [ -z "$pid" ] && return 1
53 [ ! -d /proc/$pid ] && return 1
54 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
55 # Is this the expected child?
68 # Checks for a running process named 'name' by looking for a pidfile
69 # named /var/run/openvswitch/${name}.pid
73 local pidfile=/var/run/openvswitch/${name}.pid
75 # No pidfile, probably no daemon present
76 [ ! -f "$pidfile" ] && return 1
78 # Obtain the pid and check it against the binary name
80 running_pid $pid $name || return 1
86 # Checks for a running process named 'name', by looking for a pidfile
87 # named /var/run/openvswitch/${name}.pid, and then kills it and waits
91 local pidfile=/var/run/openvswitch/${name}.pid
93 [ ! -f "$pidfile" ] && return
94 if running $name; then
96 [ -n "$DODTIME" ] && sleep "$DODTIME"
97 if running $name; then
99 [ -n "$DODTIME" ] && sleep "$DODTIME"
100 if running $name; then
101 echo "Cannot kill $name (pid=$pid)!"
131 # is_module_loaded module
133 # Returns 0 if 'module' is loaded, 1 otherwise.
137 grep -q "^$module " /proc/modules
142 # Loads 'module' into the running kernel, if it is not already loaded.
145 echo -n "Loading $module: "
146 if is_module_loaded $module; then
147 echo "already loaded, nothing to do."
148 elif modprobe $module; then
152 echo "$module has probably not been built for this kernel."
153 if ! test -d /usr/share/doc/openvswitch-datapath-source; then
154 echo "Install the openvswitch-datapath-source package, then read"
155 echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
157 echo "For instructions, read"
158 echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
164 # unload_module module
166 # Unloads 'module' from the running kernel, if it is loaded.
169 echo -n "Unloading $module: "
170 if is_module_loaded $module; then
171 if rmmod $module; then
178 echo "not loaded, nothing to do."
183 if is_module_loaded openvswitch_mod; then
184 for dp in $(ovs-dpctl dump-dps); do
185 echo -n "Deleting datapath $dp: "
186 if ovs-dpctl del-dp $dp; then
193 unload_module openvswitch_mod
197 ovs_version=`ovs-vswitchd --version | sed 's/.*) //;1q'`
198 ovs-vsctl --no-wait --timeout=5 set Open_vSwitch . \
199 ovs-version="$ovs_version"
201 if (lsb_release --id) >/dev/null 2>&1; then
202 system_type=`lsb_release --id -s`
203 system_release=`lsb_release --release -s`
204 system_codename=`lsb_release --codename -s`
205 system_version="${system_release}-${system_codename}"
207 ovs-vsctl --no-wait --timeout=5 set Open_vSwitch . \
208 system-type="$system_type" \
209 system-version="$system_version"
215 conf_file=/etc/openvswitch/conf.db
216 schema_file=/usr/share/openvswitch/vswitch.ovsschema
217 schema_ver=`ovsdb-tool schema-version "$schema_file"`
219 load_module openvswitch_mod
221 if test -n "$CORE_LIMIT"; then
222 check_op "Setting core limit to $CORE_LIMIT" ulimit -c "$CORE_LIMIT"
225 # Create an empty configuration database if it doesn't exist.
226 if test ! -e $conf_file; then
227 # Create configuration database.
228 ovsdb-tool -vANY:console:emer create $conf_file $schema_file
229 elif test "X`ovsdb-tool needs-conversion $conf_file $schema_file`" != Xno; then
230 # Back up the old version.
231 version=`ovsdb-tool db-version "$conf_file"`
232 cksum=`ovsdb-tool db-cksum "$conf_file" | awk '{print $1}'`
233 cp "$conf_file" "$conf_file.backup$version-$cksum"
235 # Upgrade or downgrade schema and compact database.
236 ovsdb-tool -vANY:console:emer convert $conf_file $schema_file
239 if test "$ENABLE_MONITOR" = y; then
240 monitor_opt=--monitor
245 if [ ! -d /var/run/openvswitch ]; then
246 install -d -m 755 -o root -g root /var/run/openvswitch
249 if [ ! -d /var/log/openvswitch ]; then
250 install -d -m 755 -o root -g root /var/log/openvswitch
253 if [ ! -d /var/log/openvswitch/cores ]; then
254 install -d -m 755 -o root -g root /var/log/openvswitch/cores
257 # Start ovsdb-server.
259 set -- "$@" $conf_file
260 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
261 set -- "$@" --log-file=/var/log/openvswitch/ovsdb-server.log
262 set -- "$@" --detach --no-chdir --pidfile $monitor_opt
263 set -- "$@" --remote punix:/var/run/openvswitch/db.sock
264 set -- "$@" --remote db:Open_vSwitch,managers
265 set -- "$@" --remote db:Open_vSwitch,manager_options
266 set -- "$@" --private-key=db:SSL,private_key
267 set -- "$@" --certificate=db:SSL,certificate
268 set -- "$@" --bootstrap-ca-cert=db:SSL,ca_cert
269 set -- "$@" $OVSDB_SERVER_OPTS
270 echo -n "Starting ovsdb-server: "
271 start-stop-daemon --start --quiet --oknodo \
272 --pidfile /var/run/openvswitch/ovsdb-server.pid \
273 --chdir /var/log/openvswitch/cores \
274 --exec $ovsdb_server -- "$@"
275 if running ovsdb-server; then
281 ovs-vsctl --no-wait --timeout=5 init -- set Open_vSwitch . db-version="$schema_ver"
285 # Start ovs-vswitchd.
287 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
288 set -- "$@" --log-file=/var/log/openvswitch/ovs-vswitchd.log
289 set -- "$@" --detach --no-chdir --pidfile $monitor_opt
290 set -- "$@" unix:/var/run/openvswitch/db.sock
291 set -- "$@" $OVS_VSWITCHD_OPTS
292 echo -n "Starting ovs-vswitchd: "
293 start-stop-daemon --start --quiet --oknodo \
294 --pidfile /var/run/openvswitch/ovs-vswitchd.pid \
295 --chdir /var/log/openvswitch/cores \
296 --exec $ovs_vswitchd -- "$@"
297 if running ovs-vswitchd; then
304 echo -n "Stopping ovs-vswitchd: "
305 start-stop-daemon --stop --quiet --oknodo --retry 5 \
306 --pidfile /var/run/openvswitch/ovs-vswitchd.pid \
307 --chdir /var/log/openvswitch/cores \
311 echo -n "Stopping ovsdb-server: "
312 start-stop-daemon --stop --quiet --oknodo --retry 5 \
313 --pidfile /var/run/openvswitch/ovsdb-server.pid \
314 --chdir /var/log/openvswitch/cores \
319 echo -n "Forcefully stopping ovs-vswitchd: "
320 force_stop ovs-vswitchd
321 if ! running ovs-vswitchd; then
327 echo -n "Forcefully stopping ovsdb-server: "
328 force_stop ovsdb-server
329 if ! running ovsdb-server; then
341 # Nothing to do, since ovs-vswitchd automatically reloads
342 # whenever its configuration changes, and ovsdb-server doesn't
343 # have anything to reload.
350 for daemon in ovs-vswitchd ovsdb-server; do
351 echo -n "$daemon is "
352 if running $daemon; then
361 N=/etc/init.d/openvswitch-switch
362 echo "Usage: $N {start|stop|restart|force-reload|status|force-stop|unload}" >&2