Skip to content

Commit aee3f7d

Browse files
authored
Merge pull request #2 from tiewei/ovs-container
Correct condition of loading ovs module
2 parents 340f7a6 + 1cfb382 commit aee3f7d

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
shfmt:
2+
go get github.com/contiv-experimental/sh/cmd/shfmt
3+
find . -type f -name "*.sh" -exec shfmt -w -i 4 -p {} \;

build_image.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ REPOSITORY="contiv/ovs"
66
IMAGE=$REPOSITORY:${NETPLUGIN_CONTAINER_TAG:-latest}
77

88
function get_image_id() {
9-
docker inspect --format '{{.ID}}' $IMAGE || :
9+
docker inspect --format '{{.ID}}' $IMAGE || :
1010
}
1111

1212
old_image=$(get_image_id)
@@ -16,6 +16,6 @@ docker build -t $IMAGE -t $REPOSITORY:latest .
1616
new_image=$(get_image_id)
1717

1818
if [ -n "$old_image" ] && [ "$old_image" != "$new_image" ]; then
19-
echo Removing old image $old_image
20-
docker rmi -f $old_image >/dev/null 2>&1 || true
19+
echo Removing old image $old_image
20+
docker rmi -f $old_image >/dev/null 2>&1 || true
2121
fi

ovsInit.sh

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,52 @@
33

44
set -euo pipefail
55

6-
if [[ $(lsmod | cut -d" " -f1 | grep -q openvswitch) -eq 1 ]]; then
7-
modprobe openvswitch
8-
sleep 2
6+
if ! lsmod | cut -d" " -f1 | grep -q openvswitch; then
7+
echo "INFO: Loading kernel module: openvswitch"
8+
modprobe openvswitch
9+
sleep 2
910
fi
1011

1112
mkdir -p /var/run/openvswitch /var/log/contiv
1213

1314
if [ -d "/etc/openvswitch" ]; then
14-
if [ -f "/etc/openvswitch/conf.db" ]; then
15-
echo "INFO: The Open vSwitch database exists"
16-
else
17-
echo "INFO: The Open VSwitch database doesn't exist"
18-
echo "INFO: Creating the Open VSwitch database..."
19-
ovsdb-tool create /etc/openvswitch/conf.db /usr/share/openvswitch/vswitch.ovsschema
20-
fi
15+
if [ -f "/etc/openvswitch/conf.db" ]; then
16+
echo "INFO: The Open vSwitch database exists"
17+
else
18+
echo "INFO: The Open VSwitch database doesn't exist"
19+
echo "INFO: Creating the Open VSwitch database..."
20+
ovsdb-tool create /etc/openvswitch/conf.db /usr/share/openvswitch/vswitch.ovsschema
21+
fi
2122
else
22-
echo "CRITICAL: Open vSwitch is not mounted from host"
23-
exit 1
23+
echo "CRITICAL: Open vSwitch is not mounted from host"
24+
exit 1
2425
fi
2526

2627
echo "INFO: Starting ovsdb-server..."
2728
ovsdb-server --remote=punix:/var/run/openvswitch/db.sock \
28-
--remote=db:Open_vSwitch,Open_vSwitch,manager_options \
29-
--private-key=db:Open_vSwitch,SSL,private_key \
30-
--certificate=db:Open_vSwitch,SSL,certificate \
31-
--bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
32-
--log-file=/var/log/contiv/ovs-db.log -vsyslog:info -vfile:info \
33-
--pidfile /etc/openvswitch/conf.db &
29+
--remote=db:Open_vSwitch,Open_vSwitch,manager_options \
30+
--private-key=db:Open_vSwitch,SSL,private_key \
31+
--certificate=db:Open_vSwitch,SSL,certificate \
32+
--bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
33+
--log-file=/var/log/contiv/ovs-db.log -vsyslog:info -vfile:info \
34+
--pidfile /etc/openvswitch/conf.db &
3435
OVSDB_PID=$!
3536

3637
echo "INFO: Starting ovs-vswitchd"
3738
ovs-vswitchd -v --pidfile --detach --log-file=/var/log/contiv/ovs-vswitchd.log \
38-
-vconsole:err -vsyslog:info -vfile:info &
39+
-vconsole:err -vsyslog:info -vfile:info &
3940
VSWITCHD_PID=$!
4041

4142
retry=0
42-
while [[ $(ovsdb-client list-dbs | grep -c Open_vSwitch) -eq 0 ]]; do
43-
if [[ ${retry} -eq 5 ]]; then
44-
echo "CRITICAL: Failed to start ovsdb in 5 seconds."
45-
exit 1
46-
else
47-
echo "INFO: Waiting for ovsdb to start..."
48-
sleep 1
49-
((retry += 1))
50-
fi
43+
while ! ovsdb-client list-dbs | grep -q Open_vSwitch; do
44+
if [[ ${retry} -eq 5 ]]; then
45+
echo "CRITICAL: Failed to start ovsdb in 5 seconds."
46+
exit 1
47+
else
48+
echo "INFO: Waiting for ovsdb to start..."
49+
sleep 1
50+
((retry += 1))
51+
fi
5152
done
5253

5354
echo "INFO: Setting OVS manager (tcp)..."
@@ -59,8 +60,8 @@ ovs-vsctl set-manager ptcp:6640
5960
STATUS=0
6061

6162
for pid in $OVSDB_PID $VSWITCHD_PID; do
62-
echo "INFO: waiting for pid $pid"
63-
wait $pid || let STATUS=1
63+
echo "INFO: waiting for pid $pid"
64+
wait $pid || let STATUS=1
6465
done
6566

6667
exit $STATUS

0 commit comments

Comments
 (0)