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 # Compact database. This is important if the old schema did not
236 # enable garbage collection (i.e. if it did not have any tables
237 # with "isRoot": true) but the new schema does. In that situation
238 # the old database may contain a transaction that creates a record
239 # followed by a transaction that creates the first use of the
240 # record. Replaying that series of transactions against the new
241 # database schema (as "convert" does) would cause the record to be
242 # dropped by the first transaction, then the second transaction
243 # would cause a referential integrity failure (for a strong
245 ovsdb-tool -vANY:console:emer compact $conf_file
247 # Upgrade or downgrade schema and compact database.
248 ovsdb-tool -vANY:console:emer convert $conf_file $schema_file
251 if test "$ENABLE_MONITOR" = y; then
252 monitor_opt=--monitor
257 if [ ! -d /var/run/openvswitch ]; then
258 install -d -m 755 -o root -g root /var/run/openvswitch
261 if [ ! -d /var/log/openvswitch ]; then
262 install -d -m 755 -o root -g root /var/log/openvswitch
265 if [ ! -d /var/log/openvswitch/cores ]; then
266 install -d -m 755 -o root -g root /var/log/openvswitch/cores
269 # Start ovsdb-server.
271 set -- "$@" $conf_file
272 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
273 set -- "$@" --log-file=/var/log/openvswitch/ovsdb-server.log
274 set -- "$@" --detach --no-chdir --pidfile $monitor_opt
275 set -- "$@" --remote punix:/var/run/openvswitch/db.sock
276 set -- "$@" --remote db:Open_vSwitch,manager_options
277 set -- "$@" --private-key=db:SSL,private_key
278 set -- "$@" --certificate=db:SSL,certificate
279 set -- "$@" --bootstrap-ca-cert=db:SSL,ca_cert
280 set -- "$@" $OVSDB_SERVER_OPTS
281 echo -n "Starting ovsdb-server: "
282 start-stop-daemon --start --quiet --oknodo \
283 --pidfile /var/run/openvswitch/ovsdb-server.pid \
284 --chdir /var/log/openvswitch/cores \
285 --exec $ovsdb_server -- "$@"
286 if running ovsdb-server; then
292 ovs-vsctl --no-wait --timeout=5 init -- set Open_vSwitch . db-version="$schema_ver"
296 # Start ovs-vswitchd.
298 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
299 set -- "$@" --log-file=/var/log/openvswitch/ovs-vswitchd.log
300 set -- "$@" --detach --no-chdir --pidfile $monitor_opt
301 set -- "$@" unix:/var/run/openvswitch/db.sock
302 set -- "$@" $OVS_VSWITCHD_OPTS
303 echo -n "Starting ovs-vswitchd: "
304 start-stop-daemon --start --quiet --oknodo \
305 --pidfile /var/run/openvswitch/ovs-vswitchd.pid \
306 --chdir /var/log/openvswitch/cores \
307 --exec $ovs_vswitchd -- "$@"
308 if running ovs-vswitchd; then
315 echo -n "Stopping ovs-vswitchd: "
316 start-stop-daemon --stop --quiet --oknodo --retry 5 \
317 --pidfile /var/run/openvswitch/ovs-vswitchd.pid \
318 --chdir /var/log/openvswitch/cores \
322 echo -n "Stopping ovsdb-server: "
323 start-stop-daemon --stop --quiet --oknodo --retry 5 \
324 --pidfile /var/run/openvswitch/ovsdb-server.pid \
325 --chdir /var/log/openvswitch/cores \
330 echo -n "Forcefully stopping ovs-vswitchd: "
331 force_stop ovs-vswitchd
332 if ! running ovs-vswitchd; then
338 echo -n "Forcefully stopping ovsdb-server: "
339 force_stop ovsdb-server
340 if ! running ovsdb-server; then
352 # Nothing to do, since ovs-vswitchd automatically reloads
353 # whenever its configuration changes, and ovsdb-server doesn't
354 # have anything to reload.
361 for daemon in ovs-vswitchd ovsdb-server; do
362 echo -n "$daemon is "
363 if running $daemon; then
372 N=/etc/init.d/openvswitch-switch
373 echo "Usage: $N {start|stop|restart|force-reload|status|force-stop|unload}" >&2