ctdb-scripts: Use ctdb_setup_state_dir()
authorMartin Schwenke <martin@meltin.net>
Wed, 7 Mar 2018 00:12:29 +0000 (11:12 +1100)
committerMartin Schwenke <martins@samba.org>
Fri, 9 Mar 2018 06:08:24 +0000 (07:08 +0100)
Replace all uses of ctdb_setup_service_state_dir() by
ctdb_setup_state_dir().

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/events.d/05.system
ctdb/config/events.d/06.nfs
ctdb/config/events.d/11.natgw
ctdb/config/events.d/13.per_ip_routing
ctdb/config/events.d/20.multipathd
ctdb/config/events.d/50.samba
ctdb/config/events.d/60.nfs
ctdb/config/statd-callout

index 3931eaca3457a7d48b56c4297d1e18735a451f29..41c582ea6d5fd3e94e804fe8d7ce2666810dad12 100755 (executable)
@@ -8,7 +8,7 @@
 
 loadconfig
 
-service_state_dir=$(ctdb_setup_service_state_dir "system-monitoring") || exit $?
+ctdb_setup_state_dir "service" "system-monitoring"
 
 validate_percentage ()
 {
@@ -38,7 +38,9 @@ check_thresholds ()
     esac
 
     _t=$(echo "$_thing" | sed -e 's@/@SLASH_@g' -e 's@ @_@g')
-    _cache="${service_state_dir}/cache_${_t}"
+    # script_state_dir set by ctdb_setup_state_dir()
+    # shellcheck disable=SC2154
+    _cache="${script_state_dir}/cache_${_t}"
     if validate_percentage "$_unhealthy_threshold" "$_thing" ; then
         if [ "$_usage" -ge "$_unhealthy_threshold" ] ; then
            echo "ERROR: ${_thing} utilization ${_usage}% >= threshold ${_unhealthy_threshold}%"
@@ -70,7 +72,7 @@ check_thresholds ()
 
 set_monitor_filsystem_usage_defaults ()
 {
-    _fs_defaults_cache="${service_state_dir}/cache_monitor_filsystem_usage_defaults"
+    _fs_defaults_cache="${script_state_dir}/cache_filsystem_usage_defaults"
 
     if [ ! -r "$_fs_defaults_cache" ] ; then
        # Determine filesystem for each database directory, generate
index e59f26534c38f36d5f6cc1dc2d13b8ef47a6fb88..833ae39a094ba24805a7b3880563d6893baaf7ea 100755 (executable)
@@ -6,12 +6,11 @@
 
 . "${CTDB_BASE}/functions"
 
-# service_name is used by various functions
-# shellcheck disable=SC2034
 service_name="nfs"
 
 loadconfig
-service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
+
+ctdb_setup_state_dir "service" "$service_name"
 
 ######################################################################
 
@@ -25,7 +24,9 @@ nfs_callout_pre ()
 
 ######################################################################
 
-nfs_callout_init "$service_state_dir"
+# script_state_dir set by ctdb_setup_state_dir()
+# shellcheck disable=SC2154
+nfs_callout_init "$script_state_dir"
 
 is_ctdb_managed_service || exit 0
 
index 4dc023a1d08c7367e22609ea3a8d63f4f83ff9d0..b256d37bceca39cba04259a1d716462a18693b6c 100755 (executable)
 
 . "${CTDB_BASE}/functions"
 
-# service_name is used by various functions
-# shellcheck disable=SC2034
-service_name=natgw
+service_name="natgw"
 
 loadconfig
 
 [ -n "$CTDB_NATGW_NODES" ] || exit 0
 export CTDB_NATGW_NODES
 
-service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
+ctdb_setup_state_dir "failover" "$service_name"
 
-natgw_cfg_new="${service_state_dir}/cfg_new"
-natgw_cfg_old="${service_state_dir}/cfg_old"
-natgw_master_old="${service_state_dir}/master_old"
+# script_state_dir set by ctdb_setup_state_dir()
+# shellcheck disable=SC2154
+natgw_cfg_new="${script_state_dir}/cfg_new"
+natgw_cfg_old="${script_state_dir}/cfg_old"
+natgw_master_old="${script_state_dir}/master_old"
 
 ctdb_natgw_slave_only ()
 {
index 191d947264db6a2afde566a16fe6be82d854a9dc..c213583b3020589f9df21b6cf4f4a91b80fda94a 100755 (executable)
@@ -7,9 +7,7 @@
 
 loadconfig
 
-# service_name is used by various functions
-# shellcheck disable=SC2034
-service_name=per_ip_routing
+service_name="per_ip_routing"
 
 # Do nothing if unconfigured 
 [ -n "$CTDB_PER_IP_ROUTING_CONF" ] || exit 0
@@ -36,7 +34,7 @@ if ! have_link_local_config && [ ! -r "$CTDB_PER_IP_ROUTING_CONF" ] ; then
     die "error: CTDB_PER_IP_ROUTING_CONF=$CTDB_PER_IP_ROUTING_CONF file not found"
 fi
 
-service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
+ctdb_setup_state_dir "failover" "$service_name"
 
 ######################################################################
 
@@ -105,7 +103,9 @@ ipv4_host_addr_to_net ()
 ensure_rt_tables ()
 {
     rt_tables="$CTDB_SYS_ETCDIR/iproute2/rt_tables"
-    rt_tables_lock="${service_state_dir}/rt_tables_lock"
+    # script_state_dir set by ctdb_setup_state_dir()
+    # shellcheck disable=SC2154
+    rt_tables_lock="${script_state_dir}/rt_tables_lock"
 
     # This file should always exist.  Even if this didn't exist on the
     # system, adding a route will have created it.  What if we startup
index 3dd58dae8ad3f7b6b0cdb6164fd542b20bda8ebb..ac3453401d1cadcaa484012923a835ee30b26f04 100755 (executable)
 
 . "${CTDB_BASE}/functions"
 
-# service_name is used by various functions
-# shellcheck disable=SC2034
 service_name="multipathd"
 
 loadconfig
 
 [ -n "$CTDB_MONITOR_MPDEVICES" ] || exit 0
 
-service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
+ctdb_setup_state_dir "service" "$service_name"
 
-multipath_fail="${service_state_dir}/fail"
+# script_state_dir set by ctdb_setup_state_dir()
+# shellcheck disable=SC2154
+multipath_fail="${script_state_dir}/fail"
 
 multipathd_check_background()
 {
index 4c32e4ee002f883aa39a502b55d8c6887417214e..ca987be3393700f2af11cd070ca09a5ea546271a 100755 (executable)
@@ -24,13 +24,11 @@ case $CTDB_INIT_STYLE in
                ;;
 esac
 
-# service_name is used by various functions
-# shellcheck disable=SC2034
 service_name="samba"
 
 loadconfig
 
-service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
+ctdb_setup_state_dir "service" "$service_name"
 
 service_start ()
 {
@@ -75,7 +73,9 @@ service_stop ()
 # Show the testparm output using a cached smb.conf to avoid delays due
 # to registry access.
 
-smbconf_cache="$service_state_dir/smb.conf.cache"
+# script_state_dir set by ctdb_setup_state_dir()
+# shellcheck disable=SC2154
+smbconf_cache="$script_state_dir/smb.conf.cache"
 
 testparm_foreground_update ()
 {
index 9b64d6e408fe203e58d91cb645377c178a4ac2df..b7775db6449f8561be0aae56891d0aa78bb924e3 100755 (executable)
@@ -6,12 +6,11 @@
 
 . "${CTDB_BASE}/functions"
 
-# service_name is used by various functions
-# shellcheck disable=SC2034
 service_name="nfs"
 
 loadconfig
-service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
+
+ctdb_setup_state_dir "service" "$service_name"
 
 ######################################################################
 
@@ -250,7 +249,9 @@ nfs_update_lock_info ()
 
 ######################################################################
 
-nfs_callout_init "$service_state_dir"
+# script_state_dir set by ctdb_setup_state_dir()
+# shellcheck disable=SC2154
+nfs_callout_init "$script_state_dir"
 
 is_ctdb_managed_service || exit 0
 
index 6c8552718b5da5f5c03789bdd467c344f517cedc..422532d2bfa1697de092c13bb5f8a9192d232187 100755 (executable)
@@ -28,10 +28,14 @@ loadconfig nfs
 
 ############################################################
 
-service_state_dir=$(ctdb_setup_service_state_dir "statd-callout") || exit $?
+ctdb_setup_state_dir "service" "nfs"
 
-cd "$service_state_dir" || \
-    die "Failed to change directory to \"${service_state_dir}\""
+# script_state_dir set by ctdb_setup_state_dir()
+# shellcheck disable=SC2154
+d="${script_state_dir}/statd-callout"
+
+mkdir -p "$d" || die "Failed to create directory \"${d}\""
+cd "$d" || die "Failed to change directory to \"${d}\""
 
 pnn=$(ctdb_get_pnn)