From: Martin Schwenke Date: Thu, 5 Mar 2026 03:37:20 +0000 (+1100) Subject: ctdb-scripts: New variable CTDB_PLATFORM_STYLE X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8044e28cb42b3b91aed1746901f47aa5439d3528;p=thirdparty%2Fsamba.git ctdb-scripts: New variable CTDB_PLATFORM_STYLE CTDB_PLATFORM_STYLE is effectively a rename of CTDB_INIT_STYLE, since a variable is needed that will be used for more purposes than "init". The new variable is automatically set when sourcing the functions file. CTDB_INIT_STYLE is now deprecated and can still be set be calling detect_init_style(). This provides backward compatibility for site-local scripts. Avoid using a state file. Given that detect_platform_style() is now only called in 1 place (i.e. immediately after its definition), the state file is an unnecessary optimisation. Also, using a state file, and setting the variable automatically when sourcing the file, means that CTDB_SCRIPT_VARDIR needs to be overridden in more UNIT test suites. For example, the tools ctdb lvs/natgw unit tests indirectly test the ctdb_lvs/ctdb_natgw scripts, which source the functions file. The previous sub-shell wasn't useful protection against a poisoned /etc/os-release file. Evil commands are evil commands, so if someone can poison that file then we're in more trouble than this script can handle. However, limiting to a couple of variables with the eval/grep trick seems like a a useful idea because those variables can then be manually unset when they are no longer needed. Using eval to do the parsing also means that full manual parsing does not need to be implemented, which would require handling (optional) quotes around values. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/config/ctdb.init b/ctdb/config/ctdb.init index 237fa6a1ef0..de03f88a7ac 100755 --- a/ctdb/config/ctdb.init +++ b/ctdb/config/ctdb.init @@ -51,9 +51,6 @@ fi load_system_config "ctdb" -detect_init_style -export CTDB_INIT_STYLE - ctdbd="${CTDBD:-/usr/sbin/ctdbd}" ctdb="${CTDB:-/usr/bin/ctdb}" pidfile="/var/run/ctdb/ctdbd.pid" @@ -64,7 +61,7 @@ start() { printf "Starting ctdbd service: " - case "$CTDB_INIT_STYLE" in + case "$CTDB_PLATFORM_STYLE" in suse) startproc "$ctdbd" rc_status -v @@ -86,7 +83,7 @@ stop() { printf "Shutting down ctdbd service: " - case "$CTDB_INIT_STYLE" in + case "$CTDB_PLATFORM_STYLE" in suse) "$ctdb" "shutdown" rc_status -v @@ -117,7 +114,7 @@ restart() check_status() { - case "$CTDB_INIT_STYLE" in + case "$CTDB_PLATFORM_STYLE" in suse) checkproc -p "$pidfile" "$ctdbd" rc_status -v diff --git a/ctdb/config/ctdb.sysconfig b/ctdb/config/ctdb.sysconfig index fc57929fc68..42ffeeda931 100644 --- a/ctdb/config/ctdb.sysconfig +++ b/ctdb/config/ctdb.sysconfig @@ -8,4 +8,4 @@ ulimit -n 1048576 ulimit -c unlimited # Useful if default detection doesn't work -# CTDB_INIT_STYLE=debian +# CTDB_PLATFORM_STYLE=debian diff --git a/ctdb/config/events/legacy/31.clamd.script b/ctdb/config/events/legacy/31.clamd.script index c4e28adc240..fd69e2ad528 100755 --- a/ctdb/config/events/legacy/31.clamd.script +++ b/ctdb/config/events/legacy/31.clamd.script @@ -6,9 +6,7 @@ . "${CTDB_BASE}/functions" -detect_init_style - -case $CTDB_INIT_STYLE in +case "$CTDB_PLATFORM_STYLE" in redhat) service_name="clamd" ;; diff --git a/ctdb/config/events/legacy/41.httpd.script b/ctdb/config/events/legacy/41.httpd.script index 048cf3286d7..7d2b642a3a8 100755 --- a/ctdb/config/events/legacy/41.httpd.script +++ b/ctdb/config/events/legacy/41.httpd.script @@ -6,9 +6,7 @@ . "${CTDB_BASE}/functions" -detect_init_style - -case $CTDB_INIT_STYLE in +case "$CTDB_PLATFORM_STYLE" in redhat) service_name="httpd" ;; diff --git a/ctdb/config/events/legacy/47.samba-dcerpcd.script b/ctdb/config/events/legacy/47.samba-dcerpcd.script index f2c0a9a23ab..cb5fe91bba4 100755 --- a/ctdb/config/events/legacy/47.samba-dcerpcd.script +++ b/ctdb/config/events/legacy/47.samba-dcerpcd.script @@ -6,9 +6,7 @@ . "${CTDB_BASE}/functions" -detect_init_style - -case $CTDB_INIT_STYLE in +case "$CTDB_PLATFORM_STYLE" in *) # distributions don't have this yet, # but assume samba-dcerpcd as service name diff --git a/ctdb/config/events/legacy/48.netbios.script b/ctdb/config/events/legacy/48.netbios.script index cf2d1450af1..f18b5afe31d 100755 --- a/ctdb/config/events/legacy/48.netbios.script +++ b/ctdb/config/events/legacy/48.netbios.script @@ -6,9 +6,7 @@ . "${CTDB_BASE}/functions" -detect_init_style - -case $CTDB_INIT_STYLE in +case $CTDB_PLATFORM_STYLE in suse) CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-nmb} ;; diff --git a/ctdb/config/events/legacy/50.samba.script b/ctdb/config/events/legacy/50.samba.script index fbffcec06e5..9005cb6b080 100755 --- a/ctdb/config/events/legacy/50.samba.script +++ b/ctdb/config/events/legacy/50.samba.script @@ -6,9 +6,7 @@ . "${CTDB_BASE}/functions" -detect_init_style - -case $CTDB_INIT_STYLE in +case "$CTDB_PLATFORM_STYLE" in suse) CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-smb} ;; diff --git a/ctdb/config/functions b/ctdb/config/functions index e6b1c848e23..99b2905d142 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -157,51 +157,54 @@ ctdb_check_args() } ############################################################## -# determine on what type of system (init style) we are running -detect_init_style() +# determine on what type of system we are running +detect_platform_style() { - _init_style_file="${CTDB_SCRIPT_VARDIR}/init-style" + CTDB_PLATFORM_STYLE="" - if [ ! -f "$_init_style_file" ]; then - if [ -n "$CTDB_INIT_STYLE" ]; then - echo "$CTDB_INIT_STYLE" >"$_init_style_file" - return - fi + _os_release="${CTDB_SYS_ETCDIR}/os-release" + if [ -f "$_os_release" ]; then + # Limit the variables that might be set + eval "$(grep '^ID=\|^ID_LIKE=' "$_os_release")" - # Subshell to contain variables in os-release file - ( - _os_release="${CTDB_SYS_ETCDIR}/os-release" - if [ -f "$_os_release" ]; then - . "$_os_release" - case "$ID" in - centos | fedora | rhel) - echo "redhat" - ;; - debian | ubuntu) - echo "debian" - ;; - sles | suse) - echo "suse" - ;; - *) - case "$ID_LIKE" in - *centos* | *rhel*) - echo "redhat" - ;; - *) - echo "$ID" - ;; - esac - ;; - esac - else - echo "WARNING: unknown distribution ${ID}" >&2 - echo "unknown" - fi - ) >"$_init_style_file" + case "$ID" in + centos | fedora | rhel) + CTDB_PLATFORM_STYLE="redhat" + ;; + debian | ubuntu) + CTDB_PLATFORM_STYLE="debian" + ;; + sles | suse) + CTDB_PLATFORM_STYLE="suse" + ;; + *) + case "$ID_LIKE" in + *centos* | *rhel*) + CTDB_PLATFORM_STYLE="redhat" + ;; + *) + CTDB_PLATFORM_STYLE="$ID" + ;; + esac + ;; + esac + + unset -v ID ID_LIKE 2>/dev/null + fi + + if [ -z "$CTDB_PLATFORM_STYLE" ]; then + echo "WARNING: unknown platform" >&2 + CTDB_PLATFORM_STYLE="unknown" fi +} + +detect_platform_style - read -r CTDB_INIT_STYLE <"$_init_style_file" +detect_init_style() +{ + # CTDB_INIT_STYLE may be used by 3rd party scripts + # shellcheck disable=SC2034 + CTDB_INIT_STYLE="$CTDB_PLATFORM_STYLE" } ###################################################### diff --git a/ctdb/doc/ctdb.sysconfig.5.xml b/ctdb/doc/ctdb.sysconfig.5.xml index b4cdaaf633e..c229b016a75 100644 --- a/ctdb/doc/ctdb.sysconfig.5.xml +++ b/ctdb/doc/ctdb.sysconfig.5.xml @@ -40,17 +40,34 @@ - CTDB_INIT_STYLE=debian|redhat|suse + CTDB_PLATFORM_STYLE=debian|redhat|suse|freebsd - This is the init style used by the Linux distribution (or + This characterises the Linux distribution (or other operating system) being used. This is usually determined dynamically by checking the system. This - variable is used by the initscript to determine which init - system primitives to use. It is also used by some - eventscripts to choose the name of initscripts for certain - services, since these can vary between distributions. + variable is used by: + + + + The initscript to determine which init system + primitives to use. + + + + + Some event scripts to determine services names, since + these can vary between distributions. + + + + + Some shell functions to determine which options to use + for certain commands. + + + If using CTDB's event scripts are unable to determine an appropriate default then this option can also be placed in @@ -59,8 +76,8 @@ 5 file. - Default: NONE. Guessed, based on features of - distribution. + Default: Based on contents of + /etc/os-release. diff --git a/ctdb/tests/UNIT/eventscripts/48.netbios.shutdown.011.sh b/ctdb/tests/UNIT/eventscripts/48.netbios.shutdown.011.sh index 06498138577..1d186992d5e 100755 --- a/ctdb/tests/UNIT/eventscripts/48.netbios.shutdown.011.sh +++ b/ctdb/tests/UNIT/eventscripts/48.netbios.shutdown.011.sh @@ -6,7 +6,7 @@ define_test "shutdown, Debian init style" setup -export EVENTSCRIPT_TESTS_INIT_STYLE="debian" +export EVENTSCRIPT_TESTS_PLATFORM_STYLE="debian" ok <&1