From 3005d149dc8c9468f545d2405f5ee9a65bdcf95a Mon Sep 17 00:00:00 2001 From: bugclerk <40872210+bugclerk@users.noreply.github.com> Date: Tue, 24 Sep 2024 07:56:21 -0700 Subject: [PATCH] NAS-131186 / 24.10.0 / Add stop-alua to scst_util.sh and call before stopping middlewared (by bmeagherix) (#14536) (#14570) * Add stop-alua to scst_util.sh and call before stopping middlewared (cherry picked from commit 600a709105e8daa4765eac86614edcecb6eb0c8f) * Increase fenced_start_loop max_retries to 4 This will help avoid fenced startup issues when a reboot is slow, for example if a large number of iSCSI targets are present. (cherry picked from commit 2b708828fa6b5db22bc3113a0246ed43775144eb) --------- Co-authored-by: Brian M (cherry picked from commit 778e91057e2172a9d76312e7f09d6d8273abb961) --- debian/debian/ix-reboot.service | 16 ++++++++++++++ debian/debian/ix-shutdown.service | 1 + debian/debian/rules | 1 + src/freenas/usr/local/bin/scst_util.sh | 21 ++++++++++++++++++- .../middlewared/plugins/failover_/event.py | 2 +- 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 debian/debian/ix-reboot.service diff --git a/debian/debian/ix-reboot.service b/debian/debian/ix-reboot.service new file mode 100644 index 000000000000..e18dee026289 --- /dev/null +++ b/debian/debian/ix-reboot.service @@ -0,0 +1,16 @@ +[Unit] +Description=Exec TrueNAS reboot tasks + +After=network.target middlewared.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=true +ExecStop=/usr/local/bin/scst_util.sh stop-alua +StandardOutput=null +StandardError=null +TimeoutStopSec=0 + +[Install] +WantedBy=multi-user.target diff --git a/debian/debian/ix-shutdown.service b/debian/debian/ix-shutdown.service index 96019d8b5622..75741f7352b1 100644 --- a/debian/debian/ix-shutdown.service +++ b/debian/debian/ix-shutdown.service @@ -7,6 +7,7 @@ After=network.target middlewared.service Type=oneshot RemainAfterExit=yes ExecStart=true +ExecStop=/usr/local/bin/scst_util.sh stop-alua ExecStop=midclt call core.event_send system.shutdown ADDED ExecStop=midclt call -job initshutdownscript.execute_init_tasks SHUTDOWN StandardOutput=null diff --git a/debian/debian/rules b/debian/debian/rules index 0cae23b14c13..f468ac111e8d 100755 --- a/debian/debian/rules +++ b/debian/debian/rules @@ -16,6 +16,7 @@ override_dh_installsystemd: dh_installsystemd --no-start -r --no-restart-after-upgrade --name=ix-netif dh_installsystemd --no-start -r --no-restart-after-upgrade --name=ix-postinit dh_installsystemd --no-start -r --no-restart-after-upgrade --name=ix-preinit + dh_installsystemd --no-start -r --no-restart-after-upgrade --name=ix-reboot dh_installsystemd --no-start -r --no-restart-after-upgrade --name=ix-shutdown dh_installsystemd --no-start -r --no-restart-after-upgrade --name=ix-ssh-keys dh_installsystemd --no-start -r --no-restart-after-upgrade --name=ix-syncdisks diff --git a/src/freenas/usr/local/bin/scst_util.sh b/src/freenas/usr/local/bin/scst_util.sh index b79634c3bef6..9c320a636fee 100755 --- a/src/freenas/usr/local/bin/scst_util.sh +++ b/src/freenas/usr/local/bin/scst_util.sh @@ -8,13 +8,32 @@ force_close() { wait } +stop_alua() { + shopt -s nullglob + + # Disable iSCSI + if [ -f /sys/kernel/scst_tgt/targets/iscsi/enabled ]; then + echo 0 > /sys/kernel/scst_tgt/targets/iscsi/enabled + fi + + # Turn off any cluster_mode in parallel + for cm in /sys/kernel/scst_tgt/devices/*/cluster_mode ; do + echo 0 > "$cm" & + done + wait +} + case "$1" in force-close) force_close rc=$? ;; + stop-alua) + stop_alua + rc=$? + ;; *) - echo "Usage: $0 {force-close}" + echo "Usage: $0 {force-close|stop-alua}" exit 2 ;; esac diff --git a/src/middlewared/middlewared/plugins/failover_/event.py b/src/middlewared/middlewared/plugins/failover_/event.py index b128c104c056..74fc8cd54713 100644 --- a/src/middlewared/middlewared/plugins/failover_/event.py +++ b/src/middlewared/middlewared/plugins/failover_/event.py @@ -326,7 +326,7 @@ def _event(self, ifname, event): elif event == 'BACKUP': return self.run_call('failover.events.vrrp_backup', fobj, ifname, event) - def fenced_start_loop(self, max_retries=3): + def fenced_start_loop(self, max_retries=4): # When active node is rebooted administratively from shell, the # fenced process will continue running on the node until systemd # finishes terminating services and actually reboots. Hence, we may