blob: e0795b0adf25774c41b7a2c14194e6625c17b3e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
#!/usr/bin/env bash
OVS_RUNDIR=/var/run/openvswitch
OVS_LOGDIR=/var/log/openvswitch
DB_NB_ADDR=${DB_NB_ADDR:-::}
DB_NB_PORT=${DB_NB_PORT:-6641}
DB_SB_ADDR=${DB_SB_ADDR:-::}
DB_SB_PORT=${DB_SB_PORT:-6642}
cmd=${1:-""}
ovn-ctl()
{
if [[ -f /usr/bin/ovn-appctl ]] ; then
echo /usr/share/ovn/scripts/ovn-ctl;
else
echo /usr/share/openvswitch/scripts/ovn-ctl;
fi
}
if [[ -f /usr/bin/ovn-appctl ]] ; then
# ovn-appctl is present. Use new ovn run dir path.
OVN_RUNDIR=/var/run/ovn
OVNCTL_PATH=/usr/share/ovn/scripts/ovn-ctl
OVN_LOGDIR=/var/log/ovn
OVN_ETCDIR=/etc/ovn
else
# ovn-appctl is not present. Use openvswitch run dir path.
OVN_RUNDIR=/var/run/openvswitch
OVNCTL_PATH=/usr/share/openvswitch/scripts/ovn-ctl
OVN_LOGDIR=/var/log/openvswitch
OVN_ETCDIR=/etc/openvswitch
fi
check_ovn_control_plane() {
$(ovn-ctl) status_northd
$(ovn-ctl) status_ovnnb
$(ovn-ctl) status_ovnsb
}
check_ovn_controller() {
$(ovn-ctl) status_controller
}
# wait for ovn-sb ready
wait_ovn_sb() {
if [[ -z "${OVN_SB_TCP_SERVICE_HOST}" ]]; then
echo "env OVN_SB_SERVICE_HOST not exists"
exit 1
fi
if [[ -z "${OVN_SB_TCP_SERVICE_PORT}" ]]; then
echo "env OVN_SB_SERVICE_PORT not exists"
exit 1
fi
while ! nc -z "${OVN_SB_TCP_SERVICE_HOST}" "${OVN_SB_TCP_SERVICE_PORT}" </dev/null;
do
echo "sleep 10 seconds, waiting for ovn-sb ${OVN_SB_TCP_SERVICE_HOST}:${OVN_SB_TCP_SERVICE_PORT} ready "
sleep 10;
done
}
start_ovs_vswitch() {
wait_ovn_sb
function quit {
/usr/share/openvswitch/scripts/ovs-ctl stop
$(ovn-ctl) stop_controller
exit 0
}
trap quit EXIT
/usr/share/openvswitch/scripts/ovs-ctl restart --no-ovs-vswitchd --system-id=random
# Restrict the number of pthreads ovs-vswitchd creates to reduce the
# amount of RSS it uses on hosts with many cores
# https://bugzilla.redhat.com/show_bug.cgi?id=1571379
# https://bugzilla.redhat.com/show_bug.cgi?id=1572797
if [[ `nproc` -gt 12 ]]; then
ovs-vsctl --no-wait set Open_vSwitch . other_config:n-revalidator-threads=4
ovs-vsctl --no-wait set Open_vSwitch . other_config:n-handler-threads=10
fi
# Start ovsdb
/usr/share/openvswitch/scripts/ovs-ctl restart --no-ovsdb-server --system-id=random
/usr/share/openvswitch/scripts/ovs-ctl --protocol=udp --dport=6081 enable-protocol
}
#cleanup_ovs_server() {
#}
#cleanup_ovs_controller() {
#}
function get_default_inteface_ipaddress {
local _ip=$1
local _default_interface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
local _ipv4address=$(ip addr show dev $_default_interface | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }')
eval $_ip="'$_ipv4address'"
}
start_ovn_control_plane() {
function quit {
$(ovn-ctl) stop_northd
exit 0
}
trap quit EXIT
$(ovn-ctl) restart_northd
ovn-nbctl set-connection ptcp:"${DB_NB_PORT}":["${DB_NB_ADDR}"]
ovn-nbctl set Connection . inactivity_probe=0
ovn-sbctl set-connection ptcp:"${DB_SB_PORT}":["${DB_SB_ADDR}"]
ovn-sbctl set Connection . inactivity_probe=0
tail -f ${OVN_LOGDIR}/ovn-northd.log
}
start_ovn_controller() {
function quit {
$(ovn-ctl) stop_controller
exit 0
}
trap quit EXIT
wait_ovn_sb
get_default_inteface_ipaddress node_ipv4_address
$(ovn-ctl) restart_controller
# Set remote ovn-sb for ovn-controller to connect to
ovs-vsctl set open . external-ids:ovn-remote=tcp:"${OVN_SB_TCP_SERVICE_HOST}":"${OVN_SB_TCP_SERVICE_PORT}"
ovs-vsctl set open . external-ids:ovn-remote-probe-interval=10000
ovs-vsctl set open . external-ids:ovn-openflow-probe-interval=180
ovs-vsctl set open . external-ids:ovn-encap-type=geneve
ovs-vsctl set open . external-ids:ovn-encap-ip=$node_ipv4_address
tail -f ${OVN_LOGDIR}/ovn-controller.log
}
set_nbclt() {
wait_ovn_sb
ovn-nbctl --db=tcp:["${OVN_NB_TCP_SERVICE_HOST}"]:"${OVN_NB_TCP_SERVICE_PORT}" --pidfile --detach --overwrite-pidfile
}
check_ovs_vswitch() {
/usr/share/openvswitch/scripts/ovs-ctl status
}
case ${cmd} in
"start_ovn_control_plane")
start_ovn_control_plane
;;
"check_ovn_control_plane")
check_ovn_control_plane
;;
"start_ovn_controller")
start_ovs_vswitch
set_nbclt
start_ovn_controller
;;
"check_ovs_vswitch")
check_ovs_vswitch
;;
"check_ovn_controller")
check_ovs_vswitch
check_ovn_controller
;;
"cleanup_ovs_controller")
cleanup_ovs_controller
;;
*)
echo "invalid command ${cmd}"
echo "valid commands: start-ovn-control-plane check_ovn_control_plane start-ovs-vswitch"
exit 0
esac
exit 0
|