]> git.proxmox.com Git - mirror_ovs.git/blame - utilities/ovs-lib.in
ovs-actions: New document describing OVS actions in detail.
[mirror_ovs.git] / utilities / ovs-lib.in
CommitLineData
20628406
BP
1# -*- sh -*-
2# vi:syntax=sh
43bb5f82
BP
3# This is a shell function library sourced by some Open vSwitch scripts.
4# It is not intended to be invoked on its own.
5
e0edde6f 6# Copyright (C) 2009, 2010, 2011, 2012 Nicira, Inc.
43bb5f82
BP
7#
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at:
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19
20## ----------------- ##
21## configure options ##
22## ----------------- ##
23
24# All of these should be substituted by the Makefile at build time.
25logdir=${OVS_LOGDIR-'@LOGDIR@'} # /var/log/openvswitch
26rundir=${OVS_RUNDIR-'@RUNDIR@'} # /var/run/openvswitch
27sysconfdir=${OVS_SYSCONFDIR-'@sysconfdir@'} # /etc
28etcdir=$sysconfdir/openvswitch # /etc/openvswitch
29datadir=${OVS_PKGDATADIR-'@pkgdatadir@'} # /usr/share/openvswitch
30bindir=${OVS_BINDIR-'@bindir@'} # /usr/bin
31sbindir=${OVS_SBINDIR-'@sbindir@'} # /usr/sbin
32
c3bf5498
BP
33# /etc/openvswitch or /var/lib/openvswitch
34if test X"$OVS_DBDIR" != X; then
35 dbdir=$OVS_DBDIR
36elif test X"$OVS_SYSCONFDIR" != X; then
37 dbdir=$OVS_SYSCONFDIR/openvswitch
38else
39 dbdir='@DBDIR@'
40fi
41
19cbf2b8
GS
42ovs_ctl_log () {
43 echo "$@" >> "${logdir}/ovs-ctl.log"
44}
45
46528f78 46ovs_ctl () {
ed87900d
GS
47 case "$@" in
48 *"=strace"*)
49 # In case of running the daemon with strace, piping the o/p causes
50 # the script to block (strace probably does not close the inherited
51 # pipe). So, do not log the o/p to ovs-ctl.log.
52 "${datadir}/scripts/ovs-ctl" "$@"
53 ;;
3b8ba174
GS
54 "status")
55 # In case of the command 'status', we should return the exit status
56 # of ovs-ctl. It is also useful to document the o/p in ovs-ctl.log.
57 display=`"${datadir}/scripts/ovs-ctl" "$@" 2>&1`
58 rc=$?
691e4755
FL
59 if test -w "${logdir}/ovs-ctl.log"; then
60 echo "${display}" | tee -a "${logdir}/ovs-ctl.log"
61 else
62 echo "${display}"
63 fi
3b8ba174
GS
64 return ${rc}
65 ;;
ed87900d
GS
66 *)
67 echo "`date -u`:$@" >> "${logdir}/ovs-ctl.log"
a34779bc 68 "${datadir}/scripts/ovs-ctl" "$@" 2>&1 | tee -a "${logdir}/ovs-ctl.log"
ed87900d
GS
69 ;;
70 esac
46528f78
GS
71}
72
43bb5f82 73VERSION='@VERSION@'
43bb5f82 74
5824c938
BP
75DAEMON_CWD=/
76
43bb5f82
BP
77LC_ALL=C; export LC_ALL
78
79## ------------- ##
80## LSB functions ##
81## ------------- ##
82
83# Use the system's own implementations if it has any.
84if test -e /etc/init.d/functions; then
85 . /etc/init.d/functions
86elif test -e /etc/rc.d/init.d/functions; then
87 . /etc/rc.d/init.d/functions
88elif test -e /lib/lsb/init-functions; then
89 . /lib/lsb/init-functions
90fi
91
92# Implement missing functions (e.g. OpenSUSE lacks 'action').
93if type log_success_msg >/dev/null 2>&1; then :; else
94 log_success_msg () {
95 printf '%s.\n' "$*"
96 }
97fi
98if type log_failure_msg >/dev/null 2>&1; then :; else
99 log_failure_msg () {
100 printf '%s ... failed!\n' "$*"
101 }
102fi
103if type log_warning_msg >/dev/null 2>&1; then :; else
104 log_warning_msg () {
105 printf '%s ... (warning).\n' "$*"
106 }
107fi
108if type action >/dev/null 2>&1; then :; else
109 action () {
110 STRING=$1
111 shift
112 "$@"
113 rc=$?
114 if test $rc = 0; then
115 log_success_msg "$STRING"
116 else
117 log_failure_msg "$STRING"
118 fi
119 return $rc
120 }
121fi
122
123## ------- ##
124## Daemons ##
125## ------- ##
126
3028ce25
BP
127pid_exists () {
128 # This is better than "kill -0" because it doesn't require permission to
129 # send a signal (so daemon_status in particular works as non-root).
130 test -d /proc/"$1"
131}
132
1f3f3f0a
CL
133pid_comm_check () {
134 [ "$1" = "`cat /proc/$2/comm`" ]
135}
136
a4d04282
DDP
137# version_geq version_a version_b
138#
139# Compare (dot separated) version numbers. Returns true (exit code 0) if
140# version_a is greater or equal than version_b, otherwise false (exit code 1).
141version_geq() {
142 echo $1 $2 | awk '{
143 n1 = split($1, a, ".");
144 n2 = split($2, b, ".");
145 n = (n1 > n2) ? n1 : n2;
146 for (i = 1; i <= n; i++) {
147 if (a[i]+0 < b[i]+0) exit 1
148 if (a[i]+0 > b[i]+0) exit 0
149 }
150 }'
151}
152
778b01a3
JS
153install_dir () {
154 DIR="$1"
03736a67 155 INSTALL_MODE="${2:-755}"
9ab5390d
AC
156 INSTALL_USER="root"
157 INSTALL_GROUP="root"
158 [ "$OVS_USER" != "" ] && INSTALL_USER="${OVS_USER%:*}"
159 [ "${OVS_USER##*:}" != "" ] && INSTALL_GROUP="${OVS_USER##*:}"
160
778b01a3 161 if test ! -d "$DIR"; then
03736a67 162 install -d -m "$INSTALL_MODE" -o "$INSTALL_USER" -g "$INSTALL_GROUP" "$DIR"
778b01a3
JS
163 restorecon "$DIR" >/dev/null 2>&1
164 fi
165}
166
43bb5f82
BP
167start_daemon () {
168 priority=$1
d0c06099
BP
169 wrapper=$2
170 shift; shift
43bb5f82 171 daemon=$1
e78eed56 172 strace=""
43bb5f82
BP
173
174 # drop core files in a sensible place
778b01a3 175 install_dir "$DAEMON_CWD"
43bb5f82
BP
176 set "$@" --no-chdir
177 cd "$DAEMON_CWD"
178
179 # log file
03736a67 180 install_dir "$logdir" "750"
43bb5f82
BP
181 set "$@" --log-file="$logdir/$daemon.log"
182
183 # pidfile and monitoring
778b01a3 184 install_dir "$rundir"
43bb5f82 185 set "$@" --pidfile="$rundir/$daemon.pid"
48458307
AC
186 set "$@" --detach
187 test X"$MONITOR" = Xno || set "$@" --monitor
43bb5f82 188
d0c06099
BP
189 # wrapper
190 case $wrapper in
191 valgrind)
192 if (valgrind --version) > /dev/null 2>&1; then
287e3bc0 193 set valgrind -q --leak-check=full --time-stamp=yes \
d0c06099
BP
194 --log-file="$logdir/$daemon.valgrind.log.%p" "$@"
195 else
196 log_failure_msg "valgrind not installed, running $daemon without it"
197 fi
198 ;;
199 strace)
200 if (strace -V) > /dev/null 2>&1; then
e78eed56
EJ
201 strace="strace -tt -T -s 256 -ff"
202 if (strace -DV) > /dev/null 2>&1; then
203 # Has the -D option.
204 set $strace -D -o "$logdir/$daemon.strace.log" "$@"
205 strace=""
206 fi
d0c06099
BP
207 else
208 log_failure_msg "strace not installed, running $daemon without it"
209 fi
210 ;;
37368939
BP
211 glibc)
212 set env MALLOC_CHECK_=2 MALLOC_PERTURB_=165 "$@"
213 ;;
d0c06099
BP
214 '')
215 ;;
216 *)
217 log_failure_msg "unknown wrapper $wrapper, running $daemon without it"
218 ;;
219 esac
220
43bb5f82
BP
221 # priority
222 if test X"$priority" != X; then
223 set nice -n "$priority" "$@"
224 fi
225
39f9a325 226 action "Starting $daemon" "$@" || return 1
e78eed56
EJ
227
228 if test X"$strace" != X; then
229 # Strace doesn't have the -D option so we attach after the fact.
230 setsid $strace -o "$logdir/$daemon.strace.log" \
231 -p `cat $rundir/$daemon.pid` > /dev/null 2>&1 &
232 fi
43bb5f82
BP
233}
234
43bb5f82
BP
235stop_daemon () {
236 if test -e "$rundir/$1.pid"; then
237 if pid=`cat "$rundir/$1.pid"`; then
a4d04282
DDP
238
239 graceful="EXIT .1 .25 .65 1"
240 actions="TERM .1 .25 .65 1 1 1 1 \
241 KILL 1 1 1 2 10 15 30 \
242 FAIL"
243 version=`ovs-appctl -T 1 -t $rundir/$1.$pid.ctl version \
244 | awk 'NR==1{print $NF}'`
245
246 # Use `ovs-appctl exit` only if the running daemon version
247 # is >= 2.5.90. This script might be used during upgrade to
248 # stop older versions of daemons which do not behave correctly
249 # with `ovs-appctl exit` (e.g. ovs-vswitchd <= 2.5.0 deletes
250 # internal ports).
251 if version_geq "$version" "2.5.90"; then
252 actions="$graceful $actions"
253 fi
254 for action in $actions; do
89bc5283
GS
255 if pid_exists "$pid" >/dev/null 2>&1; then :; else
256 return 0
257 fi
43bb5f82 258 case $action in
9b5422a9
IM
259 EXIT)
260 action "Exiting $1 ($pid)" \
7491caa3 261 ${bindir}/ovs-appctl -T 1 -t $rundir/$1.$pid.ctl exit $2
9b5422a9 262 ;;
43bb5f82
BP
263 TERM)
264 action "Killing $1 ($pid)" kill $pid
265 ;;
266 KILL)
267 action "Killing $1 ($pid) with SIGKILL" kill -9 $pid
268 ;;
269 FAIL)
270 log_failure_msg "Killing $1 ($pid) failed"
271 return 1
272 ;;
273 *)
89bc5283 274 sleep $action
43bb5f82
BP
275 ;;
276 esac
277 done
278 fi
279 fi
280 log_success_msg "$1 is not running"
281}
282
283daemon_status () {
284 pidfile=$rundir/$1.pid
285 if test -e "$pidfile"; then
286 if pid=`cat "$pidfile"`; then
3028ce25 287 if pid_exists "$pid"; then
43bb5f82
BP
288 echo "$1 is running with pid $pid"
289 return 0
290 else
291 echo "Pidfile for $1 ($pidfile) is stale"
292 fi
293 else
294 echo "Pidfile for $1 ($pidfile) exists but cannot be read"
295 fi
296 else
297 echo "$1 is not running"
298 fi
299 return 1
300}
301
302daemon_is_running () {
303 pidfile=$rundir/$1.pid
1f3f3f0a 304 test -e "$pidfile" && pid=`cat "$pidfile"` && pid_exists "$pid" && pid_comm_check $1 $pid
43bb5f82 305} >/dev/null 2>&1
7a62e5cc 306
a1d5e459
GS
307# Prints commands needed to move the ip address from interface $1 to interface
308# $2
309move_ip_address () {
310 if [ -z "$1" ] || [ -z "$2" ]; then
311 return
312 fi
7a62e5cc 313 dev="$1"
a1d5e459 314 dst="$2"
7a62e5cc
GS
315
316 # IP addresses (including IPv6).
317 echo "ip addr flush dev $dev 2>/dev/null" # Suppresses "Nothing to flush".
318 ip addr show dev $dev | while read addr; do
319 set -- $addr
320
321 # Check and trim family.
322 family=$1
323 shift
324 case $family in
325 inet | inet6) ;;
326 *) continue ;;
327 esac
328
329 # Trim device off the end--"ip" insists on having "dev" precede it.
330 addrcmd=
331 while test $# != 0; do
332 case $1 in
333 dynamic)
a6480fc6
GS
334 # XXX: According to 'man ip-address', "dynamic" is only
335 # used for ipv6 addresses. But, atleast on RHEL 7.4
336 # (iproute-3.10.0-87), it is being used for ipv4
337 # addresses assigned with dhcp.
338 if [ "$family" = "inet" ]; then
339 shift
340 continue
341 fi
7a62e5cc
GS
342 # Omit kernel-maintained route.
343 continue 2
344 ;;
345 scope)
346 if test "$2" = link -a "$family" != inet6; then
347 # Omit route derived from IP address, e.g.
348 # 172.16.0.0/16 derived from 172.16.12.34,
349 # but preserve IPv6 link-local address.
350 continue 2
351 fi
352 ;;
353 "$dev"|"$dev:"*)
354 # Address label string
a1d5e459
GS
355 label=`echo $1 | sed "s/$dev/$dst/"`
356 addrcmd="$addrcmd label $label"
7a62e5cc
GS
357 shift
358 continue
359 ;;
360 esac
361 addrcmd="$addrcmd $1"
362 shift
363 done
364 if test "$1" != "$dev"; then
365 addrcmd="$addrcmd $1"
366 fi
367
a1d5e459 368 echo ip -f $family addr add $addrcmd dev $dst
7a62e5cc
GS
369 done
370}
371
a1d5e459
GS
372# Prints commands needed to move the ip route of interface $1 to interface $2
373move_ip_routes () {
374 if [ -z "$1" ] || [ -z "$2" ]; then
375 return
376 fi
7a62e5cc 377 dev="$1"
a1d5e459 378 dst="$2"
7a62e5cc
GS
379 echo "ip route flush dev $dev proto boot 2>/dev/null" # Suppresses "Nothing to flush".
380 ip route show dev $dev | while read route; do
381 # "proto kernel" routes are installed by the kernel automatically.
382 case $route in
383 *" proto kernel "*) continue ;;
384 esac
385
a1d5e459 386 echo "ip route add $route dev $dst"
7a62e5cc
GS
387 done
388}
04b29c34 389
741fd33e 390run_as_ovsuser() {
9ab5390d 391 if [ "$OVS_USER" != "" ]; then
89caad6a
TR
392 local uid=$(id -u "${OVS_USER%:*}")
393 local gid=$(id -g "${OVS_USER%:*}")
394 local groups=$(id -G "${OVS_USER%:*}" | tr ' ' ',')
741fd33e 395 setpriv --reuid "$uid" --regid "$gid" --groups "$groups" "$@"
9ab5390d 396 else
741fd33e 397 "$@"
9ab5390d 398 fi
04b29c34
GS
399}
400
741fd33e
DM
401ovsdb_tool () {
402 run_as_ovsuser ovsdb-tool -vconsole:off "$@"
403}
404
04b29c34
GS
405create_db () {
406 DB_FILE="$1"
407 DB_SCHEMA="$2"
408 action "Creating empty database $DB_FILE" ovsdb_tool create "$DB_FILE" "$DB_SCHEMA"
409}
2db1b5d8 410
79c7961b
NS
411backup_db () {
412 # Back up the old version.
413 version=`ovsdb_tool db-version "$DB_FILE"`
414 cksum=`ovsdb_tool db-cksum "$DB_FILE" | awk '{print $1}'`
415 backup=$DB_FILE.backup$version-$cksum
416 action "Backing up database to $backup" cp "$DB_FILE" "$backup" || return 1
417}
418
2db1b5d8
GS
419upgrade_db () {
420 DB_FILE="$1"
421 DB_SCHEMA="$2"
422
423 schemaver=`ovsdb_tool schema-version "$DB_SCHEMA"`
424 if test ! -e "$DB_FILE"; then
425 log_warning_msg "$DB_FILE does not exist"
778b01a3 426 install_dir `dirname $DB_FILE`
2db1b5d8 427 create_db "$DB_FILE" "$DB_SCHEMA"
dbb5ecb4 428 elif test X"`ovsdb_tool needs-conversion "$DB_FILE" "$DB_SCHEMA"`" = Xyes; then
79c7961b 429 backup_db || return 1
2db1b5d8
GS
430
431 # Compact database. This is important if the old schema did not enable
432 # garbage collection (i.e. if it did not have any tables with "isRoot":
433 # true) but the new schema does. In that situation the old database
434 # may contain a transaction that creates a record followed by a
435 # transaction that creates the first use of the record. Replaying that
436 # series of transactions against the new database schema (as "convert"
437 # does) would cause the record to be dropped by the first transaction,
438 # then the second transaction would cause a referential integrity
439 # failure (for a strong reference).
440 #
441 # Errors might occur on an Open vSwitch downgrade if ovsdb-tool doesn't
442 # understand some feature of the schema used in the OVSDB version that
443 # we're downgrading from, so we don't give up on error.
444 action "Compacting database" ovsdb_tool compact "$DB_FILE"
445
446 # Upgrade or downgrade schema.
447 if action "Converting database schema" ovsdb_tool convert "$DB_FILE" "$DB_SCHEMA"; then
448 :
449 else
450 log_warning_msg "Schema conversion failed, using empty database instead"
451 rm -f "$DB_FILE"
452 create_db "$DB_FILE" "$DB_SCHEMA"
453 fi
454 fi
455}
36109434 456
79c7961b
NS
457upgrade_cluster () {
458 local DB_SCHEMA=$1 DB_SERVER=$2
459 local schema_name=$(ovsdb-tool schema-name $1) || return 1
460
461 action "Waiting for $schema_name to come up" ovsdb-client -t 30 wait "$DB_SERVER" "$schema_name" connected || return $?
462 local db_version=$(ovsdb-client -t 10 get-schema-version "$DB_SERVER" "$schema_name") || return $?
463 local target_version=$(ovsdb-tool schema-version "$DB_SCHEMA") || return $?
464
465 if ovsdb-tool compare-versions "$db_version" == "$target_version"; then
466 :
467 elif ovsdb-tool compare-versions "$db_version" ">" "$target_version"; then
468 log_warning_msg "Database $schema_name has newer schema version ($db_version) than our local schema ($target_version), possibly an upgrade is partially complete?"
469 else
470 action "Upgrading database $schema_name from schema version $db_version to $target_version" ovsdb-client -t 30 convert "$DB_SERVER" "$DB_SCHEMA"
471 fi
472}
473
474create_cluster () {
475 DB_FILE="$1"
476 DB_SCHEMA="$2"
477 LOCAL_ADDR="$3"
478
479 if test ! -e "$DB_FILE"; then
480 action "Creating cluster database $DB_FILE" ovsdb_tool create-cluster "$DB_FILE" "$DB_SCHEMA" "$LOCAL_ADDR"
481 elif ovsdb_tool db-is-standalone "$DB_FILE"; then
482 # Convert standalone database to clustered.
483 backup_db || return 1
484 action "Creating cluster database $DB_FILE from existing one" \
485 ovsdb_tool create-cluster "$DB_FILE" "$backup" "$LOCAL_ADDR"
486 fi
487}
488
489join_cluster() {
490 DB_FILE="$1"
491 SCHEMA_NAME="$2"
492 LOCAL_ADDR="$3"
493 REMOTE_ADDR="$4"
494
495 if test ! -e "$DB_FILE"; then
496 ovsdb_tool join-cluster "$DB_FILE" "$SCHEMA_NAME" "$LOCAL_ADDR" "$REMOTE_ADDR"
497 elif ovsdb_tool db-is-standalone "$DB_FILE"; then
498 # Backup standalone database and join cluster.
499 backup_db || return 1
500 action "Joining $DB_FILE to cluster" \
501 ovsdb_tool join-cluster "$DB_FILE" "$SCHEMA_NAME" "$LOCAL_ADDR"
502 fi
503}
504
36109434
TR
505ovs_vsctl () {
506 ovs-vsctl --no-wait "$@"
507}
508
509## ----------------- ##
510## force-reload-kmod ##
511## ----------------- ##
512
15117123
AC
513ovs_kmod_ctl () {
514 "$dir0/ovs-kmod-ctl" "$@"
515}
516
36109434
TR
517internal_interfaces () {
518 # Outputs a list of internal interfaces:
519 #
520 # - There is an internal interface for every bridge, whether it
521 # has an Interface record or not and whether the Interface
522 # record's 'type' is properly set or not.
523 #
524 # - There is an internal interface for each Interface record whose
525 # 'type' is 'internal'.
526 #
527 # But ignore interfaces that don't really exist.
528 for d in `(ovs_vsctl --bare \
529 -- --columns=name find Interface type=internal \
530 -- list-br) | sort -u`
531 do
532 if test -e "/sys/class/net/$d"; then
533 printf "%s " "$d"
534 fi
535 done
536}
537
538ovs_save () {
539 bridges=`ovs_vsctl -- --real list-br`
540 if [ -n "${bridges}" ] && \
541 "$datadir/scripts/ovs-save" "$1" ${bridges} > "$2"; then
542 chmod +x "$2"
543 return 0
544 fi
545 [ -z "${bridges}" ] && return 0
546}
547
548save_flows_if_required () {
549 if test X"$DELETE_BRIDGES" != Xyes; then
550 action "Saving flows" ovs_save save-flows "${script_flows}"
551 fi
552}
553
554save_interfaces () {
555 "$datadir/scripts/ovs-save" save-interfaces ${ifaces} \
556 > "${script_interfaces}"
557}
558
559flow_restore_wait () {
560 if test X"${OVS_VSWITCHD:-yes}" = Xyes; then
561 ovs_vsctl set open_vswitch . other_config:flow-restore-wait="true"
562 fi
563}
564
565flow_restore_complete () {
566 if test X"${OVS_VSWITCHD:-yes}" = Xyes; then
567 ovs_vsctl --if-exists remove open_vswitch . other_config \
568 flow-restore-wait="true"
569 fi
570}
571
572restore_flows () {
573 [ -x "${script_flows}" ] && \
574 action "Restoring saved flows" "${script_flows}"
575}
576
577restore_interfaces () {
578 [ ! -x "${script_interfaces}" ] && return 0
579 action "Restoring interface configuration" "${script_interfaces}"
580 rc=$?
581 if test $rc = 0; then
582 level=debug
583 else
584 level=err
585 fi
586 log="logger -p daemon.$level -t ovs-save"
587 $log "interface restore script exited with status $rc:"
588 $log -f "$script_interfaces"
589}
590
591init_restore_scripts () {
592 script_interfaces=`mktemp`
593 script_flows=`mktemp`
594 trap 'rm -f "${script_interfaces}" "${script_flows}"' 0
595}
596
597force_reload_kmod () {
598
599 if test X"${OVS_VSWITCHD:-yes}" != Xyes; then
600 log_failure_msg "Reloading of kmod without ovs-vswitchd is an error"
601 exit 1
602 fi
603
604 ifaces=`internal_interfaces`
605 action "Detected internal interfaces: $ifaces" true
606
607 init_restore_scripts
608 save_flows_if_required
609
610 # Restart the database first, since a large database may take a
611 # while to load, and we want to minimize forwarding disruption.
612 stop_ovsdb
613 start_ovsdb || return 1
614
615 stop_forwarding
616
617 if action "Saving interface configuration" save_interfaces; then
618 :
619 else
620 log_warning_msg "Failed to save configuration, not replacing kernel module"
621 start_forwarding
622 add_managers
623 exit 1
624 fi
625 chmod +x "$script_interfaces"
626
627 for dp in `ovs-dpctl dump-dps`; do
628 action "Removing datapath: $dp" ovs-dpctl del-dp "$dp"
629 done
630
e1a64872
GR
631 if test -e /sys/module/ip_gre; then
632 action "Forcing removal of ip_gre module" rmmod ip_gre
633 fi
634
635 if test -e /sys/module/gre; then
636 action "Forcing removal of gre module" rmmod gre
637 fi
638
15117123 639 ovs_kmod_ctl remove
36109434
TR
640
641 # Start vswitchd by asking it to wait till flow restore is finished.
642 flow_restore_wait
643 start_forwarding || return 1
644
645 # Restore saved flows and inform vswitchd that we are done.
646 restore_flows
647 flow_restore_complete
648 add_managers
649
650 restore_interfaces
651
652 "$datadir/scripts/ovs-check-dead-ifs"
653}
654
655## ------- ##
656## restart ##
657## ------- ##
658
659restart () {
660 if daemon_is_running ovsdb-server && daemon_is_running ovs-vswitchd; then
661 init_restore_scripts
662 if test X"${OVS_VSWITCHD:-yes}" = Xyes; then
663 save_flows_if_required
664 fi
665 fi
666
667 # Restart the database first, since a large database may take a
668 # while to load, and we want to minimize forwarding disruption.
669 stop_ovsdb
670 start_ovsdb || return 1
671
672 stop_forwarding
673
674 # Start vswitchd by asking it to wait till flow restore is finished.
675 flow_restore_wait
676 start_forwarding || return 1
677
678 # Restore saved flows and inform vswitchd that we are done.
679 restore_flows
680 flow_restore_complete
681 add_managers
682}