]> git.proxmox.com Git - mirror_ovs.git/blob - ovn/utilities/ovn-ctl
ovn-sbctl: Remove unused enum.
[mirror_ovs.git] / ovn / utilities / ovn-ctl
1 #!/bin/sh
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 case $0 in
16 */*) dir0=`echo "$0" | sed 's,/[^/]*$,,'` ;;
17 *) dir0=./ ;;
18 esac
19 . "$dir0/ovs-lib" || exit 1
20
21 for dir in "$sbindir" "$bindir" /sbin /bin /usr/sbin /usr/bin; do
22 case :$PATH: in
23 *:$dir:*) ;;
24 *) PATH=$PATH:$dir ;;
25 esac
26 done
27
28
29 ## ----- ##
30 ## start ##
31 ## ----- ##
32
33 pidfile_is_running () {
34 pidfile=$1
35 test -e "$pidfile" && pid=`cat "$pidfile"` && pid_exists "$pid"
36 } >/dev/null 2>&1
37
38 stop_ovsdb () {
39 if pidfile_is_running $DB_NB_PID; then
40 ovs-appctl -t $rundir/ovnnb_db.ctl exit
41 fi
42
43 if pidfile_is_running $DB_SB_PID; then
44 ovs-appctl -t $rundir/ovnsb_db.ctl exit
45 fi
46 }
47
48 start_ovsdb () {
49 # Check and eventually start ovsdb-server for Northbound DB
50 if ! pidfile_is_running $DB_NB_PID; then
51 upgrade_db "$DB_NB_FILE" "$DB_NB_SCHEMA" 1>/dev/null 2>/dev/null
52
53 set ovsdb-server
54
55 set "$@" --detach $OVN_NB_LOG --log-file=$OVN_NB_LOGFILE --remote=punix:$DB_NB_SOCK --remote=ptcp:$DB_NB_PORT:$DB_NB_ADDR --pidfile=$DB_NB_PID --unixctl=ovnnb_db.ctl
56
57 $@ $DB_NB_FILE
58 fi
59
60 # Check and eventually start ovsdb-server for Southbound DB
61 if ! pidfile_is_running $DB_SB_PID; then
62 upgrade_db "$DB_SB_FILE" "$DB_SB_SCHEMA" 1>/dev/null 2>/dev/null
63
64 set ovsdb-server
65
66 set "$@" --detach $OVN_SB_LOG --log-file=$OVN_SB_LOGFILE --remote=punix:$DB_SB_SOCK --remote=ptcp:$DB_SB_PORT:$DB_SB_ADDR --pidfile=$DB_SB_PID --unixctl=ovnsb_db.ctl
67 $@ $DB_SB_FILE
68 fi
69 }
70
71 status_ovsdb () {
72 if ! pidfile_is_running $DB_NB_PID; then
73 log_success_msg "OVN Northbound DB is not running"
74 else
75 log_success_msg "OVN Northbound DB is running"
76 fi
77
78 if ! pidfile_is_running $DB_SB_PID; then
79 log_success_msg "OVN Southbound DB is not running"
80 else
81 log_success_msg "OVN Southbound DB is running"
82 fi
83 }
84
85 start_northd () {
86 if test X"$OVN_MANAGE_OVSDB" = Xyes; then
87 start_ovsdb
88 fi
89
90 if ! pidfile_is_running $DB_NB_PID; then
91 log_failure_msg "OVN Northbound DB is not running"
92 exit
93 fi
94 if ! pidfile_is_running $DB_SB_PID; then
95 log_failure_msg "OVN Southbound DB is not running"
96 exit
97 fi
98
99 if daemon_is_running ovn-northd; then
100 log_success_msg "ovn-northd is already running"
101 else
102 set ovn-northd
103 if test X"$OVN_NORTHD_LOGFILE" != X; then
104 set "$@" --log-file=$OVN_NORTHD_LOGFILE
105 fi
106 set "$@" $OVN_NORTHD_LOG --ovnnb-db=unix:$DB_NB_SOCK --ovnsb-db=unix:$DB_SB_SOCK
107 OVS_RUNDIR=${OVN_RUNDIR} start_daemon "$OVN_NORTHD_PRIORITY" "$OVN_NORTHD_WRAPPER" "$@"
108 fi
109 }
110
111 start_controller () {
112 set ovn-controller "unix:$DB_SOCK"
113 set "$@" -vconsole:emer -vsyslog:err -vfile:info
114 OVS_RUNDIR=${OVN_RUNDIR} start_daemon "$OVN_CONTROLLER_PRIORITY" "$OVN_CONTROLLER_WRAPPER" "$@"
115 }
116
117 start_controller_vtep () {
118 set ovn-controller-vtep "unix:$DB_SOCK"
119 set "$@" -vconsole:emer -vsyslog:err -vfile:info
120 OVS_RUNDIR=${OVN_RUNDIR} start_daemon "$OVN_CONTROLLER_PRIORITY" "$OVN_CONTROLLER_WRAPPER" "$@"
121 }
122
123 ## ---- ##
124 ## stop ##
125 ## ---- ##
126
127 stop_northd () {
128 OVS_RUNDIR=${OVN_RUNDIR} stop_daemon ovn-northd
129
130 if test X"$OVN_MANAGE_OVSDB" = Xyes; then
131 stop_ovsdb
132 fi
133 }
134
135 stop_controller () {
136 OVS_RUNDIR=${OVN_RUNDIR} stop_daemon ovn-controller
137 }
138
139 stop_controller_vtep () {
140 OVS_RUNDIR=${OVN_RUNDIR} stop_daemon ovn-controller-vtep
141 }
142
143 ## ------- ##
144 ## restart ##
145 ## ------- ##
146
147 restart_northd () {
148 stop_northd
149 start_northd
150 }
151
152 restart_controller () {
153 stop_controller
154 start_controller
155 }
156
157 restart_controller_vtep () {
158 stop_controller_vtep
159 start_controller_vtep
160 }
161
162 restart_ovsdb () {
163 stop_ovsdb
164 start_ovsdb
165 }
166
167 ## ---- ##
168 ## main ##
169 ## ---- ##
170
171 set_defaults () {
172 OVN_MANAGE_OVSDB=yes
173
174 DB_NB_SOCK=$rundir/ovnnb_db.sock
175 DB_NB_PID=$rundir/ovnnb_db.pid
176 DB_NB_FILE=$dbdir/ovnnb_db.db
177 DB_NB_ADDR=0.0.0.0
178 DB_NB_PORT=6641
179
180 DB_SB_SOCK=$rundir/ovnsb_db.sock
181 DB_SB_PID=$rundir/ovnsb_db.pid
182 DB_SB_FILE=$dbdir/ovnsb_db.db
183 DB_SB_ADDR=0.0.0.0
184 DB_SB_PORT=6642
185
186 DB_NB_SCHEMA=$datadir/ovn-nb.ovsschema
187 DB_SB_SCHEMA=$datadir/ovn-sb.ovsschema
188
189 DB_SOCK=$rundir/db.sock
190 DB_CONF_FILE=$dbdir/conf.db
191
192 OVN_NORTHD_PRIORITY=-10
193 OVN_NORTHD_WRAPPER=
194 OVN_CONTROLLER_PRIORITY=-10
195 OVN_CONTROLLER_WRAPPER=
196
197 OVS_RUNDIR=${OVS_RUNDIR:-${rundir}}
198 OVN_RUNDIR=${OVN_RUNDIR:-${OVS_RUNDIR}}
199
200 OVN_CONTROLLER_LOG="-vconsole:emer -vsyslog:err -vfile:info"
201 OVN_NORTHD_LOG="-vconsole:emer -vsyslog:err -vfile:info"
202 OVN_NORTHD_LOGFILE=""
203 OVN_NB_LOG="-vconsole:off"
204 OVN_SB_LOG="-vconsole:off"
205 OVN_NB_LOGFILE="$logdir/ovsdb-server-nb.log"
206 OVN_SB_LOGFILE="$logdir/ovsdb-server-sb.log"
207 }
208
209 set_option () {
210 var=`echo "$option" | tr abcdefghijklmnopqrstuvwxyz- ABCDEFGHIJKLMNOPQRSTUVWXYZ_`
211 eval set=\${$var+yes}
212 eval old_value=\$$var
213 if test X$set = X || \
214 (test $type = bool && \
215 test X"$old_value" != Xno && test X"$old_value" != Xyes); then
216 echo >&2 "$0: unknown option \"$arg\" (use --help for help)"
217 return
218 fi
219 eval $var=\$value
220 }
221
222 usage () {
223 set_defaults
224 cat << EOF
225 $0: controls Open Virtual Network daemons
226 usage: $0 [OPTIONS] COMMAND
227
228 This program is intended to be invoked internally by Open Virtual Network
229 startup scripts. System administrators should not normally invoke it directly.
230
231 Commands:
232 start_northd start ovn-northd
233 start_ovsdb start ovn related ovsdb-server processes
234 start_controller start ovn-controller
235 start_controller_vtep start ovn-controller-vtep
236 stop_northd stop ovn-northd
237 stop_ovsdb stop ovn related ovsdb-server processes
238 stop_controller stop ovn-controller
239 stop_controller_vtep stop ovn-controller-vtep
240 restart_northd restart ovn-northd
241 restart_ovsdb restart ovn related ovsdb-server processes
242 restart_controller restart ovn-controller
243 restart_controller_vtep restart ovn-controller-vtep
244
245 Options:
246 --ovn-northd-priority=NICE set ovn-northd's niceness (default: $OVN_NORTHD_PRIORITY)
247 --ovn-northd-wrapper=WRAPPER run with a wrapper like valgrind for debugging
248 --ovn-controller-priority=NICE set ovn-northd's niceness (default: $OVN_CONTROLLER_PRIORITY)
249 --ovn-controller-wrapper=WRAPPER run with a wrapper like valgrind for debugging
250 --ovn-manage-ovsdb=yes|no Whether or not the OVN databases should be
251 automatically started and stopped along
252 with ovn-northd. The default is "yes". If
253 this is set to "no", the "start_ovsdb" and
254 "stop_ovsdb" commands must be used to start
255 and stop the OVN databases.
256 --ovn-controller-log=STRING ovn controller process logging params (default: $OVN_CONTROLLER_LOG)
257 --ovn-northd-log=STRING ovn northd process logging params (default: $OVN_NORTHD_LOG)
258 --ovn-northd-logfile=STRING ovn northd process log file (default: $OVN_NORTHD_LOGFILE)
259 --ovn-nb-log=STRING ovn NB ovsdb-server processes logging params (default: $OVN_NB_LOG)
260 --ovn-sb-log=STRING ovn SB ovsdb-server processes logging params (default: $OVN_SB_LOG)
261 -h, --help display this help message
262
263 File location options:
264 --db-sock=SOCKET JSON-RPC socket name (default: $DB_SOCK)
265 --db-nb-file=FILE OVN_Northbound db file (default: $DB_NB_FILE)
266 --db-sb-file=FILE OVN_Southbound db file (default: $DB_SB_FILE)
267 --db-nb-schema=FILE OVN_Northbound db file (default: $DB_NB_SCHEMA)
268 --db-sb-schema=FILE OVN_Southbound db file (default: $DB_SB_SCHEMA)
269 --db-nb-addr=ADDR OVN Northbound db ptcp address (default: $DB_NB_ADDR)
270 --db-nb-port=PORT OVN Northbound db ptcp port (default: $DB_NB_PORT)
271 --db-sb-addr=ADDR OVN Southbound db ptcp address (default: $DB_SB_ADDR)
272 --db-sb-port=PORT OVN Southbound db ptcp port (default: $DB_SB_PORT)
273 --ovn-nb-logfile=FILE OVN Northbound log file (default: $OVN_NB_LOGFILE)
274 --ovn-sb-logfile=FILE OVN Southbound log file (default: $OVN_SB_LOGFILE)
275
276 Default directories with "configure" option and environment variable override:
277 logs: /usr/local/var/log/openvswitch (--with-logdir, OVS_LOGDIR)
278 pidfiles and sockets: /usr/local/var/run/openvswitch (--with-rundir, OVS_RUNDIR)
279 ovn-nb.db: /usr/local/etc/openvswitch (--with-dbdir, OVS_DBDIR)
280 ovn-sb.db: /usr/local/etc/openvswitch (--with-dbdir, OVS_DBDIR)
281 system configuration: /usr/local/etc (--sysconfdir, OVS_SYSCONFDIR)
282 data files: /usr/local/share/openvswitch (--pkgdatadir, OVS_PKGDATADIR)
283 user binaries: /usr/local/bin (--bindir, OVS_BINDIR)
284 system binaries: /usr/local/sbin (--sbindir, OVS_SBINDIR)
285 EOF
286 }
287
288 set_defaults
289 command=
290 for arg
291 do
292 case $arg in
293 -h | --help)
294 usage
295 ;;
296 --[a-z]*=*)
297 option=`expr X"$arg" : 'X--\([^=]*\)'`
298 value=`expr X"$arg" : 'X[^=]*=\(.*\)'`
299 type=string
300 set_option
301 ;;
302 --no-[a-z]*)
303 option=`expr X"$arg" : 'X--no-\(.*\)'`
304 value=no
305 type=bool
306 set_option
307 ;;
308 --[a-z]*)
309 option=`expr X"$arg" : 'X--\(.*\)'`
310 value=yes
311 type=bool
312 set_option
313 ;;
314 -*)
315 echo >&2 "$0: unknown option \"$arg\" (use --help for help)"
316 exit 1
317 ;;
318 *)
319 if test X"$command" = X; then
320 command=$arg
321 else
322 echo >&2 "$0: exactly one non-option argument required (use --help for help)"
323 exit 1
324 fi
325 ;;
326 esac
327 done
328 case $command in
329 start_northd)
330 start_northd
331 ;;
332 start_ovsdb)
333 start_ovsdb
334 ;;
335 start_controller)
336 start_controller
337 ;;
338 start_controller_vtep)
339 start_controller_vtep
340 ;;
341 stop_northd)
342 stop_northd
343 ;;
344 stop_ovsdb)
345 stop_ovsdb
346 ;;
347 stop_controller)
348 stop_controller
349 ;;
350 stop_controller)
351 stop_controller
352 ;;
353 stop_controller_vtep)
354 stop_controller_vtep
355 ;;
356 restart_northd)
357 restart_northd
358 ;;
359 restart_ovsdb)
360 restart_ovsdb
361 ;;
362 restart_controller)
363 restart_controller
364 ;;
365 restart_controller_vtep)
366 restart_controller_vtep
367 ;;
368 status_northd)
369 daemon_status ovn-northd || exit 1
370 ;;
371 status_ovsdb)
372 status_ovsdb
373 ;;
374 status_controller)
375 daemon_status ovn-controller || exit 1
376 ;;
377 status_controller_vtep)
378 daemon_status ovn-controller-vtep || exit 1
379 ;;
380 help)
381 usage
382 ;;
383 preheat)
384 echo >&2 "$0: preheating ovn to 350 degrees F."
385 exit 1
386 ;;
387 '')
388 echo >&2 "$0: missing command name (use --help for help)"
389 exit 1
390 ;;
391 *)
392 echo >&2 "$0: unknown command \"$command\" (use --help for help)"
393 exit 1
394 ;;
395 esac