[ovs-dev] [PATCH] rhel: update openvswitch init script to include functionality in debians init script.

Duffie Cooley dcooley at nicira.com
Tue Oct 1 01:47:43 UTC 2013


From: Duffie Cooley <dcooley at nicira.com>

This pulls some of the changes to the debian init script into the rhel init
script. Specifically this is a fix for a request to make sure that the
openvswitch status command  in rhel based distros gives a useful exit
status. That was fixed in

commit 5e0c05bc058c78a11be6747f62e6ad88e5d06b70
debian: Fix exit status of openvswitch-switch init script "status"
command

This patch also pulls in the load_kmod logic in

commit 19cbf2b8a49d18eb8a8047c3b03953e6e9f0116f
debian: force-reload-kmod while package upgrading.

to enable users of rhel based distros to have the same
functionality.


Signed-off-by: Duffie Cooley <dcooley at nicira.com>
---
 rhel/etc_init.d_openvswitch | 56
++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 53 insertions(+), 3 deletions(-)

diff --git a/rhel/etc_init.d_openvswitch b/rhel/etc_init.d_openvswitch
index 7e64132..e02174d 100755
--- a/rhel/etc_init.d_openvswitch
+++ b/rhel/etc_init.d_openvswitch
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# openvswitch
+# Copyright (C) 2013 Nicira, Inc.
 #
 # chkconfig: 2345 09 91
 # description: Manage Open vSwitch kernel modules and user-space daemons
@@ -30,7 +30,29 @@
 . /usr/share/openvswitch/scripts/ovs-lib || exit 1
 test -e /etc/sysconfig/openvswitch && . /etc/sysconfig/openvswitch
 
+load_kmod () {
+    ovs_ctl load-kmod || exit $?
+}
+
 start () {
+    if ovs_ctl load-kmod; then
+        :
+    else
+        echo "Module has probably not been built for this kernel."
+    fi
     set ovs_ctl ${1-start}
     set "$@" --system-id=random
     if test X"$FORCE_COREFILES" != X; then
@@ -46,7 +68,7 @@ start () {
     set "$@" --mlockall="$VSWITCHD_MLOCKALL"
     fi
     set "$@" $OVS_CTL_OPTS
-    "$@"
+    "$@" || exit $?
 
     touch /var/lock/subsys/openvswitch
 }
@@ -57,8 +79,35 @@ stop () {
 }
 
 restart () {
-    if [ "$1" = "--save-flows=yes" ]; then
+    # OVS_FORCE_RELOAD_KMOD can be set by package postinst script.
+    if [ "$1" = "--save-flows=yes" ] || \
+        [ "${OVS_FORCE_RELOAD_KMOD}" = "no" ]; then
         start restart
+    elif [ "${OVS_FORCE_RELOAD_KMOD}" = "yes" ]; then
+        depmod -a
+
+        if [ -e /sys/module/openvswitch ]; then
+            LOADED_SRCVERSION=`cat /sys/module/openvswitch/srcversion`
+            LOADED_VERSION=`cat /sys/module/openvswitch/version`
+        elif [ -e /sys/module/openvswitch_mod ]; then
+            LOADED_SRCVERSION=`cat /sys/module/openvswitch_mod/srcversion`
+            LOADED_VERSION=`cat /sys/module/openvswitch_mod/version`
+        fi
+        SRCVERSION=`modinfo -F srcversion openvswitch 2>/dev/null`
+        VERSION=`modinfo -F version openvswitch 2>/dev/null`
+
+        ovs_ctl_log "Package upgrading:\n"\
+                    "Loaded version: ${LOADED_VERSION}
${LOADED_SRCVERSION}.\n"\
+                    "Version on disk: ${VERSION} ${SRCVERSION}."
+
+        # If the kernel module was previously loaded and it is
different than
+        # the kernel module on disk, then do a 'force-reload-kmod'.
+        if [ -n "${LOADED_SRCVERSION}" ] && [ -n "${SRCVERSION}" ] && \
+            [ "${SRCVERSION}" != "${LOADED_SRCVERSION}" ]; then
+            start force-reload-kmod
+        else
+            start restart
+        fi
     else
         stop
         start
@@ -81,6 +130,7 @@ case $1 in
         ;;
     status)
         ovs_ctl status
+        exit $?
         ;;
     version)
         ovs_ctl version
-- 
1.8.1.2




More information about the dev mailing list