This repository has been archived on 2025-02-14. You can view files and clone it, but cannot push or open issues or pull requests.
esh/esh_zfs/templates/default/zfs-scrub.erb
2025-02-15 01:05:58 +09:00

25 lines
No EOL
663 B
Text

#!/usr/bin/env bash
# https://serverfault.com/questions/538978/how-to-run-a-command-once-a-zfs-scrub-completes
set -euo pipefail
<% unless @hc_url.nil? %>
curl -m 10 --retry 5 <%= @hc_url %>/start
<% end %>
<% @pools.each_key do |pool| %>
zpool scrub <%= pool %>
# Wait until scrub for <%= pool %> is finished
while zpool status <%= pool %> | grep -q 'scan: *scrub in progress'; do
zpool status <%= pool %>
sleep 600
done
<% end %>
# Get status for all pools
zpool status
# Get stdout from journalctl
<% unless @hc_url.nil? %>
LOG=$(journalctl -o cat -u zfs-scrub.service -n 100)
curl -fsS -m 10 --retry 5 --data-raw "$LOG" <%= @hc_url %>
<% end %>
exit 0