Skip to content

Commit

Permalink
Merge pull request #382 from openshift-cherrypick-robot/cherry-pick-3…
Browse files Browse the repository at this point in the history
…80-to-18.0-fr1

[18.0-fr1] [ovsdb-server] Gracefully handle empty db file on startup
  • Loading branch information
openshift-merge-bot[bot] authored Nov 21, 2024
2 parents af14795 + cc99fa5 commit 1bf3d67
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions templates/ovncontroller/bin/functions
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OVNAvailabilityZones=${OVNAvailabilityZones:-""}
EnableChassisAsGateway=${EnableChassisAsGateway:-true}
PhysicalNetworks=${PhysicalNetworks:-""}
OVNHostName=${OVNHostName:-""}
DB_FILE=/etc/openvswitch/conf.db

ovs_dir=/var/lib/openvswitch
FLOWS_RESTORE_SCRIPT=$ovs_dir/flows-script
Expand Down Expand Up @@ -144,3 +145,10 @@ function configure_physical_networks {
fi

}

function wait_for_db_creation {
while [ ! -s ${DB_FILE} ]; do
echo "${DB_FILE} does not exist yet or is empty. Waiting..."
sleep 1
done
}
10 changes: 10 additions & 0 deletions templates/ovncontroller/bin/init-ovsdb-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@
# under the License.

set -ex
source $(dirname $0)/functions
trap wait_for_db_creation EXIT

# If db file is empty, remove it; otherwise service won't start.
# See https://issues.redhat.com/browse/FDP-689 for more details.
if ! [ -s ${DB_FILE} ]; then
rm -f ${DB_FILE}
fi
# Initialize or upgrade database if needed
CTL_ARGS="--system-id=random --no-ovs-vswitchd"
/usr/share/openvswitch/scripts/ovs-ctl start $CTL_ARGS
/usr/share/openvswitch/scripts/ovs-ctl stop $CTL_ARGS

wait_for_db_creation
trap - EXIT
2 changes: 1 addition & 1 deletion templates/ovncontroller/bin/start-ovsdb-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ source $(dirname $0)/functions
cleanup_ovsdb_server_semaphore

# Start the service
ovsdb-server /etc/openvswitch/conf.db \
ovsdb-server ${DB_FILE} \
--pidfile \
--remote=punix:/var/run/openvswitch/db.sock \
--private-key=db:Open_vSwitch,SSL,private_key \
Expand Down

0 comments on commit 1bf3d67

Please sign in to comment.