xenserver: Restart HA daemon after force-reload-kmod.
[sliver-openvswitch.git] / xenserver / etc_init.d_openvswitch
index 13b9d40..64ad52c 100755 (executable)
@@ -109,6 +109,8 @@ esac
 : ${VSWITCHD_VALGRIND_LOG:=}
 : ${VSWITCHD_VALGRIND_OPT:=}
 
+: ${OVS_XAPI_SYNC_PIDFILE:=/var/run/openvswitch/ovs-xapi-sync.pid}
+
 # Full paths to executables & modules
 ovsdb_server="/usr/sbin/ovsdb-server"
 ovsdb_tool="/usr/bin/ovsdb-tool"
@@ -260,7 +262,6 @@ function stop_daemon {
                 break
             fi
         done
-        rm -f "$pidfile"
     fi
 }
 
@@ -341,7 +342,18 @@ function start {
         cksum=`$ovsdb_tool db-cksum "$OVSDB_SERVER_DB" | awk '{print $1}'`
         cp "$OVSDB_SERVER_DB" "$OVSDB_SERVER_DB.backup$version-$cksum"
 
-        # Upgrade or downgrade schema and compact database.
+        # Compact database.  This is important if the old schema did not enable
+        # garbage collection (i.e. if it did not have any tables with "isRoot":
+        # true) but the new schema does.  In that situation the old database
+        # may contain a transaction that creates a record followed by a
+        # transaction that creates the first use of the record.  Replaying that
+        # series of transactions against the new database schema (as "convert"
+        # does) would cause the record to be dropped by the first transaction,
+        # then the second transaction would cause a referential integrity
+        # failure (for a strong reference).
+        $ovsdb_tool -vANY:console:emer compact "$OVSDB_SERVER_DB"
+
+        # Upgrade or downgrade schema.
         $ovsdb_tool -vANY:console:emer convert "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
     fi
 
@@ -371,9 +383,7 @@ function start {
 function stop {
     stop_daemon VSWITCHD "$vswitchd"
     stop_daemon OVSDB_SERVER "$ovsdb_server"
-    if [ -e /var/run/openvswitch/ovs-xapi-sync.pid ]; then
-        kill `cat /var/run/openvswitch/ovs-xapi-sync.pid`
-    fi
+    stop_daemon OVS_XAPI_SYNC ovs-xapi-sync
     rm -f /var/lock/subsys/openvswitch
 }
 
@@ -427,6 +437,14 @@ function force_reload_kmod {
     start
 
     action "Restore interface configuration from $script" $script
+
+    # Restart the high-availability daemon if it is running.  Otherwise
+    # it loses its heartbeat and reboots the system after a few minutes.
+    if pidof xhad >/dev/null && test -e /etc/xensource/xhad.conf; then
+       PATH=$PATH:/opt/xensource/xha
+       action "Stopping HA daemon" ha_stop_daemon
+       action "Starting HA daemon" ha_start_daemon
+    fi
 }
 
 case "$1" in