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
230 # If schema version changed, then back up the old version.
231 old_ver=`ovsdb-tool db-version "$conf_file"`
232 if test "X$old_ver" != "X$schema_ver"; then
233 cp "$conf_file" "$conf_file.backup$old_ver"
236 # Upgrade or downgrade schema and compact database.
237 ovsdb-tool -vANY:console:emer convert $conf_file $schema_file
240 if test "$ENABLE_MONITOR" = y; then
241 monitor_opt=--monitor
246 if [ ! -d /var/run/openvswitch ]; then
247 install -d -m 755 -o root -g root /var/run/openvswitch
250 if [ ! -d /var/log/openvswitch ]; then
251 install -d -m 755 -o root -g root /var/log/openvswitch
254 if [ ! -d /var/log/openvswitch/cores ]; then
255 install -d -m 755 -o root -g root /var/log/openvswitch/cores
258 # Start ovsdb-server.
260 set -- "$@" $conf_file
261 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
262 set -- "$@" --log-file=/var/log/openvswitch/ovsdb-server.log
263 set -- "$@" --detach --no-chdir --pidfile $monitor_opt
264 set -- "$@" --remote punix:/var/run/openvswitch/db.sock
265 set -- "$@" --remote db:Open_vSwitch,managers
266 set -- "$@" --remote db:Open_vSwitch,manager_options
267 set -- "$@" --private-key=db:SSL,private_key
268 set -- "$@" --certificate=db:SSL,certificate
269 set -- "$@" --bootstrap-ca-cert=db:SSL,ca_cert
270 set -- "$@" $OVSDB_SERVER_OPTS
271 echo -n "Starting ovsdb-server: "
272 start-stop-daemon --start --quiet --oknodo \
273 --pidfile /var/run/openvswitch/ovsdb-server.pid \
274 --chdir /var/log/openvswitch/cores \
275 --exec $ovsdb_server -- "$@"
276 if running ovsdb-server; then
282 ovs-vsctl --no-wait --timeout=5 init -- set Open_vSwitch . db-version="$schema_ver"
286 # Start ovs-vswitchd.
288 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
289 set -- "$@" --log-file=/var/log/openvswitch/ovs-vswitchd.log
290 set -- "$@" --detach --no-chdir --pidfile $monitor_opt
291 set -- "$@" unix:/var/run/openvswitch/db.sock
292 set -- "$@" $OVS_VSWITCHD_OPTS
293 echo -n "Starting ovs-vswitchd: "
294 start-stop-daemon --start --quiet --oknodo \
295 --pidfile /var/run/openvswitch/ovs-vswitchd.pid \
296 --chdir /var/log/openvswitch/cores \
297 --exec $ovs_vswitchd -- "$@"
298 if running ovs-vswitchd; then
305 echo -n "Stopping ovs-vswitchd: "
306 start-stop-daemon --stop --quiet --oknodo --retry 5 \
307 --pidfile /var/run/openvswitch/ovs-vswitchd.pid \
308 --chdir /var/log/openvswitch/cores \
312 echo -n "Stopping ovsdb-server: "
313 start-stop-daemon --stop --quiet --oknodo --retry 5 \
314 --pidfile /var/run/openvswitch/ovsdb-server.pid \
315 --chdir /var/log/openvswitch/cores \
320 echo -n "Forcefully stopping ovs-vswitchd: "
321 force_stop ovs-vswitchd
322 if ! running ovs-vswitchd; then
328 echo -n "Forcefully stopping ovsdb-server: "
329 force_stop ovsdb-server
330 if ! running ovsdb-server; then
342 # Nothing to do, since ovs-vswitchd automatically reloads
343 # whenever its configuration changes, and ovsdb-server doesn't
344 # have anything to reload.
351 for daemon in ovs-vswitchd ovsdb-server; do
352 echo -n "$daemon is "
353 if running $daemon; then
362 N=/etc/init.d/openvswitch-switch
363 echo "Usage: $N {start|stop|restart|force-reload|status|force-stop|unload}" >&2