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 ad98bc1b8e30..f1edfef9dfc2 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 5b415d22085c..ce0992820b0f 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-reporting 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 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