xenserver: Only start ovs-external-ids on XenServer.
[sliver-openvswitch.git] / xenserver / etc_init.d_openvswitch
index 9d7ad2d..31aa3fb 100755 (executable)
@@ -5,7 +5,7 @@
 # chkconfig: 2345 09 91
 # description: Manage Open vSwitch kernel modules and user-space daemons
 
-# Copyright (C) 2009, 2010 Nicira Networks, Inc.
+# Copyright (C) 2009, 2010, 2011 Nicira Networks, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+### BEGIN INIT INFO
+# Provides:          openvswitch-switch
+# Required-Start:    $network $named $remote_fs $syslog
+# Required-Stop:     $remote_fs
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Open vSwitch switch
+### END INIT INFO
+
+# source function library
+if [ -f /etc/init.d/functions ]; then
+    . /etc/init.d/functions
+elif [ -f /etc/rc.d/init.d/functions ]; then
+    . /etc/rc.d/init.d/functions
+elif [ -f /lib/lsb/init-functions ]; then
+    . /lib/lsb/init-functions
+else
+    echo "$0: missing LSB shell function library" >&2
+    exit 1
+fi
 
-. /etc/init.d/functions
+if type action >/dev/null 2>&1; then
+    :
+else
+    # SUSE lacks action
+    action() {
+       STRING=$1
+       shift
+       "$@"
+       rc=$?
+       if [ $rc -eq 0 ] ; then
+              log_success_msg $"$STRING "
+       else
+              log_failure_msg $"$STRING "
+       fi
+       return $rc
+    }
+fi
 
 . /etc/xensource-inventory
 test -e /etc/sysconfig/openvswitch && . /etc/sysconfig/openvswitch
@@ -307,7 +343,17 @@ function set_system_ids {
             external-ids:system-id="$INSTALLATION_UUID" \
             external-ids:xs-system-uuid="$INSTALLATION_UUID"
     else
-        action "Configuring Open vSwitch system IDs" false
+       if test -f /etc/openvswitch/install_uuid.conf; then
+            . /etc/openvswitch/install_uuid.conf
+       elif INSTALLATION_UUID=`uuidgen`; then
+           echo "INSTALLATION_UUID=$INSTALLATION_UUID" > /etc/openvswitch/install_uuid.conf
+       else
+           log_failure_msg "missing uuidgen, could not generate system UUID"
+           return
+        fi
+        $vsctl --no-wait --timeout=5 set Open_vSwitch . \
+            external-ids:system-id="$INSTALLATION_UUID"
+        action "Configuring Open vSwitch system IDs" true
     fi
 }
 
@@ -361,10 +407,12 @@ function start {
         start_brcompatd
     fi
 
-    # Start daemon to monitor external ids
-    PYTHONPATH=/usr/share/openvswitch/python \
-               /usr/share/openvswitch/scripts/ovs-external-ids \
-               --pidfile --detach $monitor_opt "$VSWITCHD_OVSDB_SERVER"
+    if [ -f /etc/xensource-inventory ]; then
+        # Start daemon to monitor external ids
+        PYTHONPATH=/usr/share/openvswitch/python \
+                   /usr/share/openvswitch/scripts/ovs-external-ids \
+                   --pidfile --detach $monitor_opt "$VSWITCHD_OVSDB_SERVER"
+    fi
 
     touch /var/lock/subsys/openvswitch
 }