Eventscripts: add a debug() function and call ctdb_set_current_debuglevel()
authorMartin Schwenke <martin@meltin.net>
Tue, 16 Aug 2011 23:44:11 +0000 (09:44 +1000)
committerMartin Schwenke <martin@meltin.net>
Wed, 17 Aug 2011 00:39:35 +0000 (10:39 +1000)
The debug function passes its arguments to echo if
$CTDB_CURRENT_DEBUGLEVEL is >= 4 (i.e. DEBUG).  If no args are given
then use stdin - this allows the function to be used with here
documents.

To ensure $CTDB_CURRENT_DEBUGLEVEL is set,
ctdb_set_current_debuglevel() is called near the end of the functions
file.

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

index 26b282aa994b7e595fe9cc9b8013b71297e7a843..c6cddd462d6152c5b3110faa1fd46985d5ca2d02 100755 (executable)
@@ -68,6 +68,20 @@ ctdb_set_current_debuglevel ()
     . "$_f"
 }
 
+debug ()
+{
+    if [ $CTDB_CURRENT_DEBUGLEVEL -ge 4 ] ; then
+       # If there are arguments then echo them.  Otherwise expect to
+       # use stdin, which allows us to pass lots of debug using a
+       # here document.
+       if [ -n "$1" ] ; then
+           echo "DEBUG: $*"
+       elif ! tty -s ; then
+           sed -e 's@^@DEBUG: @'
+       fi
+    fi
+}
+
 ##############################################################
 # determine on what type of system (init style) we are running
 detect_init_style() {
@@ -1125,6 +1139,11 @@ update_tickles ()
        done
 }
 
+# We'll call this here to ensure $CTDB_CURRENT_DEBUGLEVEL is set.
+# This gives us a chance to override the debug level using a file in
+# $CTDB_BASE/rc.local.d/.
+ctdb_set_current_debuglevel
+
 script_name="${0##*/}"       # basename
 service_name="$script_name"  # default is just the script name
 service_fail_limit=1