mirror of
https://github.com/samba-team/samba.git
synced 2025-02-02 09:47:23 +03:00
ctdb-scripts: Factor out function ctdb_setup_state_dir()
This allows state directories for scripts other than services. ctdb_setup_state_dir() takes 2 mandatory arguments. Unlike ctdb_setup_service_state_dir(), this does not print the directory name but sets a global variable. The intention is to go back to a more sensible style of usage. This will require a shellcheck directive before the first use, such as: # Set by ctdb_setup_state_dir # shellcheck disable=SC2154 foo="${script_state_dir}/bar" An alternative would be something like the following, which tricks shellcheck into believing the variable is set: ctdb_setup_state_dir "service" "foo" # Shellcheck script_state_dir="$script_state_dir" However, this is more cryptic. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
parent
2089961346
commit
fac6d23d27
@ -723,15 +723,32 @@ ctdb_counter_get () {
|
||||
|
||||
########################################################
|
||||
|
||||
# ctdb_setup_state_dir <type> <name>
|
||||
# Sets/creates script_state_dir)
|
||||
ctdb_setup_state_dir ()
|
||||
{
|
||||
[ $# -eq 2 ] || die "usage: ctdb_setup_state_dir <type> <name>"
|
||||
|
||||
_type="$1"
|
||||
_name="$2"
|
||||
|
||||
script_state_dir="${CTDB_SCRIPT_VARDIR}/${_type}/${_name}"
|
||||
|
||||
mkdir -p "$script_state_dir" || \
|
||||
die "Error creating script state dir \"${script_state_dir}\""
|
||||
}
|
||||
|
||||
# ctdb_setup_service_state_dir [name]
|
||||
# Sets/creates/prints script_state_dir)
|
||||
ctdb_setup_service_state_dir ()
|
||||
{
|
||||
# Some code passes an argument
|
||||
# shellcheck disable=SC2120
|
||||
_s="${1:-${service_name}}"
|
||||
|
||||
_service_state_dir="${CTDB_SCRIPT_VARDIR}/service_state/${_s}"
|
||||
mkdir -p "$_service_state_dir" ||
|
||||
die "Error creating state dir \"${_service_state_dir}\""
|
||||
ctdb_setup_state_dir "service" "$_s"
|
||||
|
||||
echo "$_service_state_dir"
|
||||
echo "$script_state_dir"
|
||||
}
|
||||
|
||||
##################################################################
|
||||
|
Loading…
x
Reference in New Issue
Block a user