Shutdown after completion of SCRUB

Problem/Justification
I have a TrueNAS installation on a backup NAS that boots once a week. Id like to have it set to shutdown after the SCRUB operation is complete.

Impact
Good for power savings, especially in Europe!

1 Like

I donā€™t see any specific reason to add a shutdown option for scrubs in TrueNAS. There already is a way to check;
zpool wait -t scrub POOL

In theory, you may want to wait til all background tasks are complete;
zpool wait POOL
See manual page for zpool-wait for the other background tasks, like resilver or free.

Putting those in a boot time startup script, with a wait both before and after, should suffice:
1 - Wait til scrub starts
2 - Wait til scrub finishes, zpool wait -t scrub POOL
3 - Wait a bit, (a minute or 2?), in case user changes their mind about shutting down
4 - Shutdown

4 Likes

Beyond my technical ability unfortunately!

For a feature request to be accepted, it should apply to more than a few people. Not sure this will end up being such. However, you will need to advocate for the change.

Also, donā€™t forget to ā€œVoteā€ for your own feature request.

1 Like

Iā€™d argue that a ā€œShutdown after background tasks completeā€ option should be available under the GUI Power button. After all, it seems we are strongly encouraged to do everything from the GUI, so the GUI should have the functionality to handle a wide array of tasks the user may want to perform. While many of us techy types can easily jump into a shell, the user base would expand quicker if the GUI was more capable.

Iā€™m in a similar situation to mrjay with a pair of systems where one is for daily backups and a second that will be an ā€œarchiveā€ system that will be the replication target of the backup datasets with the archive replications running about twice a month. It would be great if I could just turn on the archive system on archive days, and have it power itself down after my replications and any housekeeping tasks are complete. Iā€™ll probably try to use the suggestion Arwen has provided for now, but Iā€™d love to be able to let the GUI (and the GUI guardrails) handle it for me.

Understood.

However, the paying customers, (Enterprise Data Center), likely wonā€™t use such, or very rarely. Even then, the scripted version I outlined would likely be more flexible and easy to implement, (for Enterprise Data Center users).

Your GUI Shutdown option to wait any background tasks to complete, is actually a bit cleaner. It may not fit the fully automated concept that @mrjay84 seemed to want. Yet it would accomplish the result, shutdown after scrub completes.

I found this online, changed the pool name as instructed however it failed with ā€œnon-zero exit statusā€

#!/bin/bash



zpool scrub tank  # Replace "tank" with your pool name



while [[ $(zpool status tank | grep "scrub in progress") ]]; do

    sleep 60

done



shutdown -p now 

Full error


cannot scrub Datastore: currently scrubbing; use 'zpool scrub -s' to cancel scrub
unrecognized command 'stat6us'
usage: zpool command args ...
where 'command' is one of the following:

	version [-j]

	create [-fnd] [-o property=value] ... 
	    [-O file-system-property=value] ... 
	    [-m mountpoint] [-R root] <pool> <vdev> ...
... 124 more lines ...
	set <property=value> <pool>
	set <vdev_property=value> <pool> <vdev>
	sync [pool] ...

	wait [-Hp] [-T d|u] [-t <activity>[,...]] <pool> [interval]

	ddtprune -d|-p <amount> <pool>

For further help on a command or topic, run: zpool help [<topic>]
shutdown: invalid option -- 'p'

Check your typingā€¦

zpool wait -t scrub tank, as pointed to by @Arwen, is a much cleaner way than this ā€˜whileā€™ loop to wait for scrub completion. Although I would remove the ā€˜-t scrubā€™ to account for any other activity, including a possible resilver, before really powering off the backup NAS.

#! /bin/sh
zpool scrub Datastore
zpool wait Datastore
shutdown -p 10
3 Likes

Been looking at creating a backup server but canā€™t figure out how I would kick the whole process off automatically. I want it to:

  • Power on by WoL or BIOS schedule.
  • SSH into server and pull snapshot.
  • Send email that job completed.
  • Start Scrub.
  • Send email upon scrub completion.
  • Shutdown.

The problem I have is how do I even start any script I would write? I canā€™t use systemd which would be the ideal way because it would log it in the journal. But because updates wipe out anything that I would insert into the /etc/systemd/system folder that option is out the window. I canā€™t use the pre/post init script feature because it has a timeout and wonā€™t allow a null. The only option is to start it manually, which is not feasible.

How would I do this?

Why not?

Iā€™ve routinely used such one shot startup scripts using:

#!/bin/bash
#
/usr/bin/at now + 1 minutes /root/bin/MyBkScript 2>&1 >/dev/null

It might take testing, but there are options. Unix is like that. Canā€™t do it one way, generally there is another way.

1 Like

According to the manual about Init/Shutdown Scripts:

Enter the number of seconds after the script runs that the command should stop in Timeout.

I want the script to stop when itā€™s done and that doesnā€™t seem possible. Unless I enter for example 10 in timeout and that would run the entire script and then 10 seconds later it would timeout? Iā€™m just confused as the script could take quite some time to run depending on how long the scrub takes.

Also how would you go about running a post init script that runs indefinitely or until shutdown?

@Arwen Just showed you a way. Read the post again (and possibly man at).

1 Like