]> git.proxmox.com Git - mirror_ovs.git/blame - tutorial/ovs-sandbox
ovs-sandbox: add delay before running ovs-vsctl
[mirror_ovs.git] / tutorial / ovs-sandbox
CommitLineData
eeecce05
BP
1#! /bin/sh
2#
6b2771c3 3# Copyright (c) 2013, 2015 Nicira, Inc.
eeecce05
BP
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at:
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17set -e
18
8da7cd8c 19run() {
eeecce05
BP
20 (cd "$sandbox" && "$@") || exit 1
21}
22
8da7cd8c 23run_xterm() {
4cf272aa
AZ
24 title=$1;
25 shift
26 run xterm -T "$title" -e "$@" &
8da7cd8c
AZ
27}
28
29rungdb() {
30 under_gdb=$1
31 shift
32 # Remove the --detach and to put the process under gdb control.
33 # Also remove --vconsole:off to allow error message to show up
34 # on the console.
35 # Use "DISPLAY" variable to determine out if X is supported
36 if $under_gdb && [ "$DISPLAY" ]; then
37 args=`echo $@ |sed s/--detach//g | sed s/--vconsole:off//g`
fdc14c7b
RB
38 xterm_title=$1
39 run_xterm $xterm_title gdb -ex run --args $args
8da7cd8c
AZ
40 else
41 run $@
42 fi
43}
44
4b814d41
AZ
45gdb_vswitchd=false
46gdb_ovsdb=false
eeecce05
BP
47builddir=
48srcdir=
49schema=
50installed=false
51built=false
8da7cd8c 52
eeecce05
BP
53for option; do
54 # This option-parsing mechanism borrowed from a Autoconf-generated
55 # configure script under the following license:
56
57 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
58 # 2002, 2003, 2004, 2005, 2006, 2009, 2013 Free Software Foundation, Inc.
59 # This configure script is free software; the Free Software Foundation
60 # gives unlimited permission to copy, distribute and modify it.
61
62 # If the previous option needs an argument, assign it.
63 if test -n "$prev"; then
64 eval $prev=\$option
65 prev=
66 continue
67 fi
68 case $option in
69 *=*) optarg=`expr "X$option" : '[^=]*=\(.*\)'` ;;
70 *) optarg=yes ;;
71 esac
72
73 case $dashdash$option in
74 --)
75 dashdash=yes ;;
76 -h|--help)
77 cat <<EOF
78ovs-sandbox, for starting a sandboxed dummy Open vSwitch environment
79usage: $0 [OPTION...]
80
81If you run ovs-sandbox from an OVS build directory, it uses the OVS that
82you built. Otherwise, if you have an installed Open vSwitch, it uses
83the installed version.
84
85These options force ovs-sandbox to use a particular OVS build:
86 -b, --builddir=DIR specify Open vSwitch build directory
87 -s, --srcdir=DIR specify Open vSwitch source directory
88These options force ovs-sandbox to use an installed Open vSwitch:
89 -i, --installed use installed Open vSwitch
8da7cd8c 90 -g, --gdb-vswitchd run ovs-vswitchd under gdb
4b814d41 91 -d, --gdb-ovsdb run ovsdb-server under gdb
eeecce05
BP
92 -S, --schema=FILE use FILE as vswitch.ovsschema
93
94Other options:
95 -h, --help Print this usage message.
96EOF
97 exit 0
98 ;;
99
100 --b*=*)
101 builddir=$optarg
102 built=:
103 ;;
104 -b|--b*)
105 prev=builddir
106 built=:
107 ;;
108 --sr*=*)
109 srcdir=$optarg
110 built=false
111 ;;
112 -s|--sr*)
113 prev=srcdir
114 built=false
115 ;;
116 -i|--installed)
117 installed=:
118 ;;
119 --sc*=*)
120 schema=$optarg
121 installed=:
122 ;;
123 -S|--sc*)
124 prev=schema
125 installed=:
126 ;;
8da7cd8c
AZ
127 -g|--gdb-v*)
128 gdb_vswitchd=true
129 ;;
4b814d41
AZ
130 -d|--gdb-o*)
131 gdb_ovsdb=true
132 ;;
eeecce05
BP
133 -*)
134 echo "unrecognized option $option (use --help for help)" >&2
135 exit 1
136 ;;
137 *)
138 echo "$option: non-option arguments not supported (use --help for help)" >&2
139 exit 1
140 ;;
141 esac
142 shift
143done
144
145if $installed && $built; then
146 echo "sorry, conflicting options (use --help for help)" >&2
147 exit 1
148elif $installed || $built; then
149 :
150elif test -e vswitchd/ovs-vswitchd; then
151 built=:
152 builddir=.
153elif (ovs-vswitchd --version) >/dev/null 2>&1; then
154 installed=:
155else
156 echo "can't find an OVS build or install (use --help for help)" >&2
157 exit 1
158fi
159
160if $built; then
161 if test ! -e "$builddir"/vswitchd/ovs-vswitchd; then
162 echo "$builddir does not appear to be an OVS build directory" >&2
163 exit 1
164 fi
165 builddir=`cd $builddir && pwd`
166
167 # Find srcdir.
168 case $srcdir in
169 '')
170 srcdir=$builddir
9feb1017 171 if test ! -e "$srcdir"/WHY-OVS.md; then
eeecce05
BP
172 srcdir=`cd $builddir/.. && pwd`
173 fi
174 ;;
175 /*) ;;
176 *) srcdir=`pwd`/$srcdir ;;
177 esac
178 schema=$srcdir/vswitchd/vswitch.ovsschema
179 if test ! -e "$schema"; then
180 echo >&2 'source directory not found, please use --srcdir'
181 exit 1
182 fi
183
184 # Put built tools early in $PATH.
185 if test ! -e $builddir/vswitchd/ovs-vswitchd; then
186 echo >&2 'build not found, please change set $builddir or change directory'
187 exit 1
188 fi
189 PATH=$builddir/ovsdb:$builddir/vswitchd:$builddir/utilities:$PATH
190 export PATH
191else
192 case $schema in
193 '')
194 for schema in \
195 /usr/local/share/openvswitch/vswitch.ovsschema \
196 /usr/share/openvswitch/vswitch.ovsschema \
197 none; do
198 if test -r $schema; then
199 break
200 fi
201 done
202 ;;
203 /*) ;;
204 *) schema=`pwd`/$schema ;;
205 esac
206 if test ! -r "$schema"; then
207 echo "can't find vswitch.ovsschema, please specify --schema" >&2
208 exit 1
209 fi
210fi
211
212# Create sandbox.
213rm -rf sandbox
214mkdir sandbox
215sandbox=`cd sandbox && pwd`
216
217# Set up environment for OVS programs to sandbox themselves.
218OVS_RUNDIR=$sandbox; export OVS_RUNDIR
219OVS_LOGDIR=$sandbox; export OVS_LOGDIR
220OVS_DBDIR=$sandbox; export OVS_DBDIR
221OVS_SYSCONFDIR=$sandbox; export OVS_SYSCONFDIR
222
223if $built; then
224 # Easy access to OVS manpages.
348f8282 225 (cd "$builddir" && ${MAKE} install-man mandir="$sandbox"/man)
eeecce05
BP
226 MANPATH=$sandbox/man:; export MANPATH
227fi
228
229# Ensure cleanup.
230trap 'kill `cat "$sandbox"/*.pid`' 0 1 2 3 13 14 15
231
232# Create database and start ovsdb-server.
233touch "$sandbox"/.conf.db.~lock~
431ad535 234run ovsdb-tool create conf.db "$schema"
4b814d41 235rungdb $gdb_ovsdb ovsdb-server --detach --no-chdir --pidfile -vconsole:off --log-file \
eeecce05
BP
236 --remote=punix:"$sandbox"/db.sock
237
e43a07ba
AZ
238#Add a small delay to allow ovsdb-server to launch.
239sleep 0.1
240
241#Wait for ovsdb-server to finish launching.
242if test ! -e "$sandbox"/db.sock; then
243 echo -n "Waiting for ovsdb-server to start..."
244 while test ! -e "$sandbox"/db.sock; do
245 sleep 1;
246 done
247 echo " Done"
248fi
249
6b2771c3
BP
250# Initialize database.
251run ovs-vsctl --no-wait -- init
252
eeecce05 253# Start ovs-vswitchd.
8da7cd8c 254rungdb $gdb_vswitchd ovs-vswitchd --detach --no-chdir --pidfile -vconsole:off --log-file \
eeecce05
BP
255 --enable-dummy=override -vvconn -vnetdev_dummy
256
257cat <<EOF
258
259
260
261----------------------------------------------------------------------
262You are running in a dummy Open vSwitch environment. You can use
263ovs-vsctl, ovs-ofctl, ovs-appctl, and other tools to work with the
264dummy switch.
265
266Log files, pidfiles, and the configuration database are in the
267"sandbox" subdirectory.
268
269Exit the shell to kill the running daemons.
270EOF
271
272status=0; $SHELL || status=$?
273
274cat <<EOF
275----------------------------------------------------------------------
276
277
278
279EOF
280
281exit $status