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