Skip to content

Instantly share code, notes, and snippets.

@mnl
Created November 13, 2022 21:33
Show Gist options
  • Save mnl/24ccb25d07b36be3a4c418b97981b7c1 to your computer and use it in GitHub Desktop.
Save mnl/24ccb25d07b36be3a4c418b97981b7c1 to your computer and use it in GitHub Desktop.
Wait for activating systemd mount units
#!/bin/bash
wait_for_mounts() {
local timestamp=$(date -d 1min +%s)
timeleft() {
[[ $(date +%s) -lt $timestamp ]] && return 0
return 1 # Timeout, $timestamp passed
}
activating_mounts() {
# Get list of units
systemctl list-units --type mount --state activating --quiet
}
while timeleft; do
[[ -n $(activating_mounts) ]] || break
sleep 1
done
# Check again and use that as return status
[[ -z $(activating_mounts) ]]
}
wait_for_mounts || echo "Timed out waiting for mounts" >&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment