ctdb-scripts: New internal variable CTDB_SCRIPT_VARDIR
authorMartin Schwenke <martin@meltin.net>
Thu, 13 Aug 2015 05:54:20 +0000 (15:54 +1000)
committerMichael Adam <obnox@samba.org>
Tue, 15 Sep 2015 06:56:21 +0000 (08:56 +0200)
Clearly identifies where all state files from scripts should go and
allows that location to be easily changed.  This patch should not
change any behaviour (outside of eventscript unit tests, where a
clearer location is now used).

CTDB_VARDIR should no longer be overridden.  Continue to set
CTDB_DBDIR and similar to override database location in unit tests.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Jose A. Rivera <jarrpa@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
ctdb/config/events.d/00.ctdb
ctdb/config/events.d/README
ctdb/config/functions
ctdb/doc/ctdbd.conf.5.xml
ctdb/tests/eventscripts/scripts/local.sh

index 98fb50d5032066cc1047ee028bb374c6d00b6c7d..99a0c713bfc7f4b79d6fe904508c39c5bf2805a2 100755 (executable)
@@ -123,12 +123,9 @@ ctdb_check_args "$@"
 case "$1" in
      init)
         # make sure we have a blank state directory for the scripts to work with
-       rm -rf $CTDB_VARDIR/state
-       mkdir -p $CTDB_VARDIR/state || {
-           ret=$?
-           echo "mkdir -p $CTDB_VARDIR/state - failed - $ret"
-           exit $ret
-       }
+       rm -rf "$CTDB_SCRIPT_VARDIR"
+       mkdir -p "$CTDB_SCRIPT_VARDIR" || \
+           die "mkdir -p ${CTDB_SCRIPT_VARDIR} - failed - ${ret}" $?
 
        if select_tdb_checker ; then
            check_persistent_databases || exit $?
index ea9048fcf00edd01b439eade7edace5373841b86..c7c3deaa44fa75459f447f8d8743a04d6f3a31a0 100644 (file)
@@ -31,7 +31,7 @@ init
        and prepare the basic setup.
        At this stage 'ctdb' commands won't work.
 
-       Example: 00.ctdb cleans up $CTDB_VARDIR/state
+       Example: 00.ctdb cleans up $CTDB_SCRIPT_VARDIR
 
 setup
        This event does not take any additional arguments.
index 9711c516deefef88dbb60a9b7367644206e3ab12..eabd056fdc33de7a49f662aaaf9fa31730f66335 100755 (executable)
@@ -2,10 +2,12 @@
 
 # utility functions for ctdb event scripts
 
+CTDB_VARDIR="/usr/local/var/lib/ctdb"
+
 # Only (and always) override these variables in test code
 
-if [ -z "$CTDB_VARDIR" ] ; then
-    CTDB_VARDIR="/usr/local/var/lib/ctdb"
+if [ -z "$CTDB_SCRIPT_VARDIR" ] ; then
+    CTDB_SCRIPT_VARDIR="/usr/local/var/lib/ctdb/state"
 fi
 
 if [ -z "$CTDB_ETCDIR" ] ; then
@@ -203,7 +205,7 @@ nice_service()
 # This sets $pnn - this avoid an unnecessary subprocess.
 ctdb_get_pnn ()
 {
-    _pnn_file="$CTDB_VARDIR/state/my-pnn"
+    _pnn_file="${CTDB_SCRIPT_VARDIR}/my-pnn"
     if [ ! -f "$_pnn_file" ] ; then
        ctdb pnn | sed -e 's@.*:@@' >"$_pnn_file"
     fi
@@ -306,7 +308,7 @@ ctdb_check_directories()
 _ctdb_check_tcp_common ()
 {
     assert_service_name
-    _d="${CTDB_VARDIR}/state/failcount"
+    _d="${CTDB_SCRIPT_VARDIR}/failcount"
     _ctdb_service_started_file="${_d}/${service_name}.started"
 }
 
@@ -610,7 +612,7 @@ flush_route_cache ()
 # Simple counters
 _ctdb_counter_common () {
     _service_name="${1:-${service_name:-${script_name}}}"
-    _counter_file="${CTDB_VARDIR}/state/failcount/${_service_name}"
+    _counter_file="${CTDB_SCRIPT_VARDIR}/failcount/${_service_name}"
     mkdir -p "${_counter_file%/*}" # dirname
 }
 ctdb_counter_init () {
@@ -661,7 +663,7 @@ ctdb_check_counter () {
 
 ctdb_setup_service_state_dir ()
 {
-    service_state_dir="$CTDB_VARDIR/state/service_state/${1:-${service_name}}"
+    service_state_dir="${CTDB_SCRIPT_VARDIR}/service_state/${1:-${service_name}}"
     mkdir -p "$service_state_dir" || {
        echo "Error creating state dir \"$service_state_dir\""
        exit 1
@@ -673,7 +675,7 @@ ctdb_setup_service_state_dir ()
 
 _ctdb_managed_common ()
 {
-    _ctdb_managed_file="${CTDB_VARDIR}/state/managed_history/${service_name}"
+    _ctdb_managed_file="${CTDB_SCRIPT_VARDIR}/managed_history/${service_name}"
 }
 
 ctdb_service_managed ()
@@ -700,7 +702,7 @@ is_ctdb_previously_managed_service ()
 
 _ctdb_service_reconfigure_common ()
 {
-    _d="${CTDB_VARDIR}/state/service_status/${service_name}"
+    _d="${CTDB_SCRIPT_VARDIR}/service_status/${service_name}"
     mkdir -p "$_d"
     _ctdb_service_reconfigure_flag="$_d/reconfigure"
 }
@@ -1039,7 +1041,7 @@ update_tickles ()
 {
        _port="$1"
 
-       tickledir="$CTDB_VARDIR/state/tickles"
+       tickledir="${CTDB_SCRIPT_VARDIR}/tickles"
        mkdir -p "$tickledir"
 
        ctdb_get_pnn
index da2471e8e29ef0726914abbd37dc02ea3e303c7e..57835e442be9e71b0e60252283ab735f274a6280 100644 (file)
        </listitem>
       </varlistentry>
 
-      <varlistentry>
-       <term>CTDB_VARDIR=<parameter>DIRECTORY</parameter></term>
-       <listitem>
-         <para>
-           DIRECTORY containing CTDB files that are modified at
-           runtime.
-         </para>
-         <para>
-           Defaults to <filename>/usr/local/var/lib/ctdb</filename>.
-         </para>
-       </listitem>
-      </varlistentry>
-
-
     </variablelist>
   </refsect1>
 
@@ -1657,6 +1643,19 @@ CTDB_SET_MonitorInterval=20
        </listitem>
       </varlistentry>
 
+      <varlistentry>
+       <term>CTDB_VARDIR=<parameter>DIRECTORY</parameter></term>
+       <listitem>
+         <para>
+           DIRECTORY containing CTDB files that are modified at
+           runtime.
+         </para>
+         <para>
+           Defaults to <filename>/usr/local/var/lib/ctdb</filename>.
+         </para>
+       </listitem>
+      </varlistentry>
+
     </variablelist>
 
   </refsect1>
index 6f3c34e17f612ea6685e4c1268d1e8dcce43f2b2..bed602a881347709a2041ef01c122c064eb9b5c3 100644 (file)
@@ -25,13 +25,13 @@ if [ -d "$EVENTSCRIPTS_TESTS_VAR_DIR" -a \
     rm -r "$EVENTSCRIPTS_TESTS_VAR_DIR"
 fi
 mkdir -p "$EVENTSCRIPTS_TESTS_VAR_DIR"
-export CTDB_VARDIR="$EVENTSCRIPTS_TESTS_VAR_DIR/ctdb"
+export CTDB_SCRIPT_VARDIR="$EVENTSCRIPTS_TESTS_VAR_DIR/script-state"
 
 export CTDB_LOGGING="file:${EVENTSCRIPTS_TESTS_VAR_DIR}/log.ctdb"
 touch "${CTDB_LOGGING#file:}" || \
     die "Unable to setup logging for \"$CTDB_LOGGING\""
 
-if [ -d "${TEST_SUBDIR}/etc" ] ; then    
+if [ -d "${TEST_SUBDIR}/etc" ] ; then
     cp -a "${TEST_SUBDIR}/etc" "$EVENTSCRIPTS_TESTS_VAR_DIR"
     export CTDB_ETCDIR="${EVENTSCRIPTS_TESTS_VAR_DIR}/etc"
 else
@@ -291,8 +291,8 @@ ctdb_set_pnn ()
     export FAKE_CTDB_PNN="$1"
     echo "Setting up PNN ${FAKE_CTDB_PNN}"
 
-    export CTDB_VARDIR="$EVENTSCRIPTS_TESTS_VAR_DIR/ctdb/${FAKE_CTDB_PNN}"
-    mkdir -p "$CTDB_VARDIR"
+    export CTDB_SCRIPT_VARDIR="$EVENTSCRIPTS_TESTS_VAR_DIR/script-state/${FAKE_CTDB_PNN}"
+    mkdir -p "$CTDB_SCRIPT_VARDIR"
 }
 
 setup_ctdb ()