xenserver: Be compatible with non-XenServer func libraries in init script.
authorBen Pfaff <blp@nicira.com>
Wed, 5 Jan 2011 19:00:41 +0000 (11:00 -0800)
committerBen Pfaff <blp@nicira.com>
Fri, 7 Jan 2011 18:31:29 +0000 (10:31 -0800)
XenServer has its function library in /etc/init.d/functions but other
distros have it in different places.  Currently this init script is
specifically intended for XenServer but adding compatibility with other
distros seems like a worthwhile goal.

Also, SuSE does not have the "action" function, so test whether it is
implemented and when not supply a fallback.

Signed-off-by: Patrick Mullaney <pm.mullaney@gmail.com>
[changed to only define action() if not already defined]
Signed-off-by: Ben Pfaff <blp@nicira.com>
xenserver/etc_init.d_openvswitch

index c77132a308a223df904efc0cab6e40490b0ae07d..e404c60e2a905188f44cc66e2df8194841dd7d55 100755 (executable)
 # 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