Eventscript functions: add $CTDB_ETCDIR and hook service() functions.
authorMartin Schwenke <martin@meltin.net>
Tue, 7 Jun 2011 05:57:29 +0000 (15:57 +1000)
committerMartin Schwenke <martin@meltin.net>
Wed, 3 Aug 2011 06:45:54 +0000 (16:45 +1000)
* $CTDB_ETCDIR defaults to /etc but can be changed for testing.  All
  hard-coded instances of /etc have been changed to $CTDB_ETCDIR.
  This includes references to /etc/init.d and /etc/sysconfig.

* service() and nice_service() functions now call new function
  _service().  This makes it easier to override these functions (say,
  in rc.local) for testing and call most of the existing functionality
  using _service().

Signed-off-by: Martin Schwenke <martin@meltin.net>
config/functions

index 06442d01b7a15d874478ff03efc34d201a3d4a80..bd8d38d6dbac55b7ea1355dfdb4880dfcb236e72 100755 (executable)
@@ -5,6 +5,9 @@ PATH=/bin:/usr/bin:/usr/sbin:/sbin:$PATH
 [ -z "$CTDB_VARDIR" ] && {
     export CTDB_VARDIR="/var/ctdb"
 }
+[ -z "$CTDB_ETCDIR" ] && {
+    export CTDB_ETCDIR="/etc"
+}
 
 #######################################
 # pull in a system config file, if any
@@ -19,11 +22,10 @@ _loadconfig() {
        loadconfig "ctdb"
     fi
 
-
-    if [ -f /etc/sysconfig/$1 ]; then
-       . /etc/sysconfig/$1
-    elif [ -f /etc/default/$1 ]; then
-       . /etc/default/$1
+    if [ -f $CTDB_ETCDIR/sysconfig/$1 ]; then
+       . $CTDB_ETCDIR/sysconfig/$1
+    elif [ -f $CTDB_ETCDIR/default/$1 ]; then
+       . $CTDB_ETCDIR/default/$1
     elif [ -f $CTDB_BASE/sysconfig/$1 ]; then
        . $CTDB_BASE/sysconfig/$1
     fi
@@ -50,7 +52,10 @@ detect_init_style() {
 
 ######################################################
 # simulate /sbin/service on platforms that don't have it
-service() { 
+# _service() makes it easier to hook the service() function for
+# testing.
+_service ()
+{
   _service_name="$1"
   _op="$2"
 
@@ -58,30 +63,26 @@ service() {
   [ -z "$_service_name" ] && return
 
   if [ -x /sbin/service ]; then
-      /sbin/service "$_service_name" "$_op"
-  elif [ -x /etc/init.d/$_service_name ]; then
-      /etc/init.d/$_service_name "$_op"
-  elif [ -x /etc/rc.d/init.d/$_service_name ]; then
-      /etc/rc.d/init.d/$_service_name "$_op"
+      $_nice /sbin/service "$_service_name" "$_op"
+  elif [ -x $CTDB_ETCDIR/init.d/$_service_name ]; then
+      $_nice $CTDB_ETCDIR/init.d/$_service_name "$_op"
+  elif [ -x $CTDB_ETCDIR/rc.d/init.d/$_service_name ]; then
+      $_nice $CTDB_ETCDIR/rc.d/init.d/$_service_name "$_op"
   fi
 }
 
+service()
+{
+    _nice=""
+    _service "$@"
+}
+
 ######################################################
 # simulate /sbin/service (niced) on platforms that don't have it
-nice_service() { 
-  _service_name="$1"
-  _op="$2"
-
-  # do nothing, when no service was specified
-  [ -z "$_service_name" ] && return
-
-  if [ -x /sbin/service ]; then
-      nice /sbin/service "$_service_name" "$_op"
-  elif [ -x /etc/init.d/$_service_name ]; then
-      nice /etc/init.d/$_service_name "$_op"
-  elif [ -x /etc/rc.d/init.d/$_service_name ]; then
-      nice /etc/rc.d/init.d/$_service_name "$_op"
-  fi
+nice_service()
+{
+    _nice="nice"
+    _service "$@"
 }
 
 ######################################################
@@ -362,10 +363,10 @@ tickle_tcp_connections() {
 ########################################################
 startstop_nfs() {
        PLATFORM="unknown"
-       [ -x /etc/init.d/nfsserver ] && {
+       [ -x $CTDB_ETCDIR/init.d/nfsserver ] && {
                PLATFORM="sles"
        }
-       [ -x /etc/init.d/nfslock ] && {
+       [ -x $CTDB_ETCDIR/init.d/nfslock ] && {
                PLATFORM="rhel"
        }
 
@@ -418,10 +419,10 @@ startstop_nfs() {
 ########################################################
 startstop_nfslock() {
        PLATFORM="unknown"
-       [ -x /etc/init.d/nfsserver ] && {
+       [ -x $CTDB_ETCDIR/init.d/nfsserver ] && {
                PLATFORM="sles"
        }
-       [ -x /etc/init.d/nfslock ] && {
+       [ -x $CTDB_ETCDIR/init.d/nfslock ] && {
                PLATFORM="rhel"
        }