From: Martin Schwenke Date: Sat, 28 Feb 2026 10:48:06 +0000 (+1100) Subject: ctdb-scripts: Reformat with "shfmt -w -i 0 -fn" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c30d4c182dfca9f666b24eee1e84a6e9a90bbca;p=thirdparty%2Fsamba.git ctdb-scripts: Reformat with "shfmt -w -i 0 -fn" Best reviewed with "git show -w" or similar. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/config/ctdb.init b/ctdb/config/ctdb.init index 6a7f7812394..237fa6a1ef0 100755 --- a/ctdb/config/ctdb.init +++ b/ctdb/config/ctdb.init @@ -19,20 +19,20 @@ ### END INIT INFO # Source function library. -if [ -f /etc/init.d/functions ] ; then - # Red Hat - . /etc/init.d/functions -elif [ -f /etc/rc.d/init.d/functions ] ; then - # Red Hat - . /etc/rc.d/init.d/functions -elif [ -f /etc/rc.status ] ; then - # SUSE - . /etc/rc.status - rc_reset - LC_ALL=en_US.UTF-8 -elif [ -f /lib/lsb/init-functions ] ; then - # Debian - . /lib/lsb/init-functions +if [ -f /etc/init.d/functions ]; then + # Red Hat + . /etc/init.d/functions +elif [ -f /etc/rc.d/init.d/functions ]; then + # Red Hat + . /etc/rc.d/init.d/functions +elif [ -f /etc/rc.status ]; then + # SUSE + . /etc/rc.status + rc_reset + LC_ALL=en_US.UTF-8 +elif [ -f /lib/lsb/init-functions ]; then + # Debian + . /lib/lsb/init-functions fi # Avoid using root's TMPDIR @@ -45,8 +45,8 @@ unset TMPDIR load_system_config "network" # check networking is up (for redhat) -if [ "$NETWORKING" = "no" ] ; then - exit 0 +if [ "$NETWORKING" = "no" ]; then + exit 0 fi load_system_config "ctdb" @@ -62,60 +62,60 @@ pidfile="/var/run/ctdb/ctdbd.pid" start() { - printf "Starting ctdbd service: " + printf "Starting ctdbd service: " - case "$CTDB_INIT_STYLE" in + case "$CTDB_INIT_STYLE" in suse) - startproc "$ctdbd" - rc_status -v - ;; + startproc "$ctdbd" + rc_status -v + ;; redhat) - daemon --pidfile "$pidfile" "$ctdbd" - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1 - return $RETVAL - ;; + daemon --pidfile "$pidfile" "$ctdbd" + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1 + return $RETVAL + ;; debian) - eval start-stop-daemon --start --quiet --background --exec "$ctdbd" - ;; - esac + eval start-stop-daemon --start --quiet --background --exec "$ctdbd" + ;; + esac } stop() { - printf "Shutting down ctdbd service: " + printf "Shutting down ctdbd service: " - case "$CTDB_INIT_STYLE" in + case "$CTDB_INIT_STYLE" in suse) - "$ctdb" "shutdown" - rc_status -v - ;; + "$ctdb" "shutdown" + rc_status -v + ;; redhat) - "$ctdb" "shutdown" - RETVAL=$? - # Common idiom in Red Hat init scripts - success() always - # succeeds so this does behave like if-then-else - # shellcheck disable=SC2015 - [ $RETVAL -eq 0 ] && success || failure - echo "" - [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb - return $RETVAL - ;; + "$ctdb" "shutdown" + RETVAL=$? + # Common idiom in Red Hat init scripts - success() always + # succeeds so this does behave like if-then-else + # shellcheck disable=SC2015 + [ $RETVAL -eq 0 ] && success || failure + echo "" + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb + return $RETVAL + ;; debian) - "$ctdb" "shutdown" - log_end_msg $? - ;; - esac + "$ctdb" "shutdown" + log_end_msg $? + ;; + esac } restart() { - stop - start + stop + start } -check_status () +check_status() { case "$CTDB_INIT_STYLE" in suse) @@ -134,28 +134,29 @@ check_status () ############################################################ case "$1" in - start) - start +start) + start ;; - stop) - stop +stop) + stop ;; - restart|reload|force-reload) - restart +restart | reload | force-reload) + restart ;; - status) - check_status +status) + check_status ;; - condrestart|try-restart) - if check_status >/dev/null ; then - restart +condrestart | try-restart) + if check_status >/dev/null; then + restart fi ;; - cron) +cron) # used from cron to auto-restart ctdb - check_status >/dev/null 2>&1 || restart + check_status >/dev/null 2>&1 || restart ;; - *) +*) echo "Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}" exit 1 + ;; esac diff --git a/ctdb/config/events/legacy/05.system.script b/ctdb/config/events/legacy/05.system.script index 47f3acbce44..66f9f4ffeb5 100755 --- a/ctdb/config/events/legacy/05.system.script +++ b/ctdb/config/events/legacy/05.system.script @@ -52,9 +52,9 @@ check_thresholds() if validate_percentage "$_unhealthy_threshold" "$_thing"; then if [ "$_usage" -ge "$_unhealthy_threshold" ]; then printf 'ERROR: %s utilization %d%% >= threshold %d%%\n' \ - "$_thing" \ - "$_usage" \ - "$_unhealthy_threshold" + "$_thing" \ + "$_usage" \ + "$_unhealthy_threshold" # Only run unhealthy callout if passing the # unhealthy threshold. That is, if the # previous usage was below the threshold. @@ -72,18 +72,18 @@ check_thresholds() return fi printf 'WARNING: %s utilization %d%% >= threshold %d%%\n' \ - "$_thing" \ - "$_usage" \ - "$_warn_threshold" + "$_thing" \ + "$_usage" \ + "$_warn_threshold" echo "$_usage" >"$_cache" else if [ ! -r "$_cache" ]; then return fi printf 'NOTICE: %s utilization %d%% < threshold %d%%\n' \ - "$_thing" \ - "$_usage" \ - "$_warn_threshold" + "$_thing" \ + "$_usage" \ + "$_warn_threshold" rm -f "$_cache" fi fi @@ -129,7 +129,7 @@ monitor_filesystem_usage() sed -n -e 's@.*[[:space:]]\([[:digit:]]*\)%.*@\1@p') if [ -z "$_fs_usage" ]; then printf 'WARNING: Unable to get FS utilization for %s\n' \ - "$_fs_mount" + "$_fs_mount" continue fi diff --git a/ctdb/config/events/legacy/31.clamd.script b/ctdb/config/events/legacy/31.clamd.script index 966f63cc30a..c4e28adc240 100755 --- a/ctdb/config/events/legacy/31.clamd.script +++ b/ctdb/config/events/legacy/31.clamd.script @@ -1,7 +1,7 @@ #!/bin/sh # event script to manage clamd in a cluster environment -[ -n "$CTDB_BASE" ] || \ +[ -n "$CTDB_BASE" ] || CTDB_BASE=$(d="$(dirname "$0")" && cd -P "$d/../../" && pwd) . "${CTDB_BASE}/functions" @@ -21,7 +21,7 @@ load_script_options case "$1" in startup) - service "$service_name" stop > /dev/null 2>&1 + service "$service_name" stop >/dev/null 2>&1 service "$service_name" start || exit $? ;; @@ -30,8 +30,8 @@ shutdown) ;; monitor) - ctdb_check_unix_socket "$CTDB_CLAMD_SOCKET" || exit $? - ;; + ctdb_check_unix_socket "$CTDB_CLAMD_SOCKET" || exit $? + ;; esac exit 0 diff --git a/ctdb/config/events/legacy/40.vsftpd.script b/ctdb/config/events/legacy/40.vsftpd.script index 6497c715888..89119d4d065 100755 --- a/ctdb/config/events/legacy/40.vsftpd.script +++ b/ctdb/config/events/legacy/40.vsftpd.script @@ -1,14 +1,14 @@ #!/bin/sh # event strict to manage vsftpd in a cluster environment -[ -n "$CTDB_BASE" ] || \ +[ -n "$CTDB_BASE" ] || CTDB_BASE=$(d="$(dirname "$0")" && cd -P "$d/../../" && pwd) . "${CTDB_BASE}/functions" service_name="vsftpd" -service_reconfigure () +service_reconfigure() { # shellcheck disable=SC2317 # Called indirectly via ctdb_service_reconfigure() @@ -23,7 +23,7 @@ port_21="vsftpd listening on TCP port 21" case "$1" in startup) - service "$service_name" stop > /dev/null 2>&1 + service "$service_name" stop >/dev/null 2>&1 service "$service_name" start failcount_init "$port_21" ;; @@ -32,18 +32,18 @@ shutdown) service "$service_name" stop ;; -takeip|releaseip) +takeip | releaseip) ctdb_service_set_reconfigure ;; ipreallocated) - if ctdb_service_needs_reconfigure ; then + if ctdb_service_needs_reconfigure; then ctdb_service_reconfigure fi ;; monitor) - if ctdb_check_tcp_ports 21 ; then + if ctdb_check_tcp_ports 21; then failcount_reset "$port_21" else # Set defaults, if unset diff --git a/ctdb/config/events/legacy/41.httpd.script b/ctdb/config/events/legacy/41.httpd.script index 51d85947ff3..048cf3286d7 100755 --- a/ctdb/config/events/legacy/41.httpd.script +++ b/ctdb/config/events/legacy/41.httpd.script @@ -1,7 +1,7 @@ #!/bin/sh # event script to manage httpd in a cluster environment -[ -n "$CTDB_BASE" ] || \ +[ -n "$CTDB_BASE" ] || CTDB_BASE=$(d="$(dirname "$0")" && cd -P "$d/../../" && pwd) . "${CTDB_BASE}/functions" @@ -12,7 +12,7 @@ case $CTDB_INIT_STYLE in redhat) service_name="httpd" ;; -suse|debian|*) +suse | debian | *) service_name="apache2" ;; esac @@ -23,24 +23,25 @@ ctdb_setup_state_dir "service" "$service_name" # RHEL5 sometimes use a SIGKILL to terminate httpd, which then leaks # semaphores. This is a hack to clean them up. -cleanup_httpd_semaphore_leak() { - killall -q -0 "$service_name" || - for i in $(ipcs -s | awk '$3 == "apache" { print $2 }') ; do - ipcrm -s "$i" - done +cleanup_httpd_semaphore_leak() +{ + killall -q -0 "$service_name" || + for i in $(ipcs -s | awk '$3 == "apache" { print $2 }'); do + ipcrm -s "$i" + done } ########## -service_start () +service_start() { - cleanup_httpd_semaphore_leak - service $service_name start + cleanup_httpd_semaphore_leak + service $service_name start } -service_stop () +service_stop() { - service $service_name stop - killall -q -9 $service_name || true + service $service_name stop + killall -q -9 $service_name || true } case "$1" in @@ -54,17 +55,17 @@ shutdown) ;; monitor) - if ctdb_check_tcp_ports 80 >/dev/null 2>/dev/null ; then + if ctdb_check_tcp_ports 80 >/dev/null 2>/dev/null; then ctdb_counter_init else ctdb_counter_incr num_fails=$(ctdb_counter_get) - if [ "$num_fails" -eq 2 ] ; then + if [ "$num_fails" -eq 2 ]; then echo "HTTPD is not running. Trying to restart HTTPD." service_stop service_start exit 0 - elif [ "$num_fails" -ge 5 ] ; then + elif [ "$num_fails" -ge 5 ]; then echo "HTTPD is not running. Trying to restart HTTPD." service_stop service_start @@ -75,4 +76,3 @@ monitor) esac exit 0 - diff --git a/ctdb/config/events/legacy/47.samba-dcerpcd.script b/ctdb/config/events/legacy/47.samba-dcerpcd.script index fae9ee9f0f0..f2c0a9a23ab 100755 --- a/ctdb/config/events/legacy/47.samba-dcerpcd.script +++ b/ctdb/config/events/legacy/47.samba-dcerpcd.script @@ -1,7 +1,7 @@ #!/bin/sh # ctdb event script for SAMBA DCERPCD Services -[ -n "$CTDB_BASE" ] || \ +[ -n "$CTDB_BASE" ] || CTDB_BASE=$(d="$(dirname "$0")" && cd -P "$d/../../" && pwd) . "${CTDB_BASE}/functions" @@ -9,41 +9,41 @@ detect_init_style case $CTDB_INIT_STYLE in - *) - # distributions don't have this yet, - # but assume samba-dcerpcd as service name - CTDB_SERVICE_SAMBA_DCERPCD=${CTDB_SERVICE_SAMBA_DCERPCD:-samba-dcerpcd} - ;; +*) + # distributions don't have this yet, + # but assume samba-dcerpcd as service name + CTDB_SERVICE_SAMBA_DCERPCD=${CTDB_SERVICE_SAMBA_DCERPCD:-samba-dcerpcd} + ;; esac load_script_options -service_start () +service_start() { - # make sure samba-dcerpcd is not already started - service "$CTDB_SERVICE_SAMBA_DCERPCD" stop > /dev/null 2>&1 - killall -0 -q samba-dcerpcd && { - sleep 1 - # make absolutely sure samba-dcerpcd is dead - killall -q -9 samba-dcerpcd - } + # make sure samba-dcerpcd is not already started + service "$CTDB_SERVICE_SAMBA_DCERPCD" stop >/dev/null 2>&1 + killall -0 -q samba-dcerpcd && { + sleep 1 + # make absolutely sure samba-dcerpcd is dead + killall -q -9 samba-dcerpcd + } - # start Samba dcerpcd service. Start it reniced, as under very heavy load - # the number of smbd processes will mean that it leaves few cycles - # for anything else - nice_service "$CTDB_SERVICE_SAMBA_DCERPCD" start || die "Failed to start samba-dcerpcd" + # start Samba dcerpcd service. Start it reniced, as under very heavy load + # the number of smbd processes will mean that it leaves few cycles + # for anything else + nice_service "$CTDB_SERVICE_SAMBA_DCERPCD" start || die "Failed to start samba-dcerpcd" } -service_stop () +service_stop() { - service "$CTDB_SERVICE_SAMBA_DCERPCD" stop + service "$CTDB_SERVICE_SAMBA_DCERPCD" stop } -service_status () +service_status() { - service "$CTDB_SERVICE_SAMBA_DCERPCD" status > /dev/null - test $? = 0 && return 0 - service "$CTDB_SERVICE_SAMBA_DCERPCD" status + service "$CTDB_SERVICE_SAMBA_DCERPCD" status >/dev/null + test $? = 0 && return 0 + service "$CTDB_SERVICE_SAMBA_DCERPCD" status } ########################### diff --git a/ctdb/config/events/legacy/48.netbios.script b/ctdb/config/events/legacy/48.netbios.script index ed0f871f939..cf2d1450af1 100755 --- a/ctdb/config/events/legacy/48.netbios.script +++ b/ctdb/config/events/legacy/48.netbios.script @@ -1,7 +1,7 @@ #!/bin/sh # ctdb event script for Netbios Name Services -[ -n "$CTDB_BASE" ] || \ +[ -n "$CTDB_BASE" ] || CTDB_BASE=$(d="$(dirname "$0")" && cd -P "$d/../../" && pwd) . "${CTDB_BASE}/functions" @@ -9,16 +9,16 @@ detect_init_style case $CTDB_INIT_STYLE in - suse) - CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-nmb} - ;; - debian) - CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-nmbd} - ;; - *) - # Use redhat style as default: - CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-nmb} - ;; +suse) + CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-nmb} + ;; +debian) + CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-nmbd} + ;; +*) + # Use redhat style as default: + CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-nmb} + ;; esac service_name="netbios" @@ -27,32 +27,32 @@ load_script_options ctdb_setup_state_dir "service" "$service_name" -service_start () +service_start() { - # make sure nmbd is not already started - service "$CTDB_SERVICE_NMB" stop > /dev/null 2>&1 - killall -0 -q nmbd && { - sleep 1 - # make absolutely sure nmbd is dead - killall -q -9 nmbd - } - - # start Samba nmbd service. Start it reniced, as under very heavy load - # the number of smbd processes will mean that it leaves few cycles - # for anything else - nice_service "$CTDB_SERVICE_NMB" start || die "Failed to start nmbd" + # make sure nmbd is not already started + service "$CTDB_SERVICE_NMB" stop >/dev/null 2>&1 + killall -0 -q nmbd && { + sleep 1 + # make absolutely sure nmbd is dead + killall -q -9 nmbd + } + + # start Samba nmbd service. Start it reniced, as under very heavy load + # the number of smbd processes will mean that it leaves few cycles + # for anything else + nice_service "$CTDB_SERVICE_NMB" start || die "Failed to start nmbd" } -service_stop () +service_stop() { - service "$CTDB_SERVICE_NMB" stop + service "$CTDB_SERVICE_NMB" stop } -service_status () +service_status() { - service "$CTDB_SERVICE_NMB" status > /dev/null - test $? = 0 && return 0 - service "$CTDB_SERVICE_NMB" status + service "$CTDB_SERVICE_NMB" status >/dev/null + test $? = 0 && return 0 + service "$CTDB_SERVICE_NMB" status } ########################### diff --git a/ctdb/config/events/legacy/50.samba.script b/ctdb/config/events/legacy/50.samba.script index 7da0c399d59..fbffcec06e5 100755 --- a/ctdb/config/events/legacy/50.samba.script +++ b/ctdb/config/events/legacy/50.samba.script @@ -32,8 +32,7 @@ generate_smb_interfaces_config() get_public_ifaces pub_iface_list=$public_ifaces public_ifaces="" - for iface in $pub_iface_list; - do + for iface in $pub_iface_list; do public_ifaces="$public_ifaces \"$iface;options=dynamic\"" done @@ -41,7 +40,7 @@ generate_smb_interfaces_config() public_ifaces="$public_ifaces $CTDB_SAMBA_INTERFACES_EXTRA" fi -cat < "$CTDB_SAMBA_INTERFACES_FILE" + cat <"$CTDB_SAMBA_INTERFACES_FILE" bind interfaces only = yes interfaces = lo $public_ifaces EOT @@ -132,13 +131,13 @@ testparm_background_update() testparm_foreground_update "$_timeout" >/dev/null 2>&1