Created
November 13, 2022 21:33
-
-
Save mnl/24ccb25d07b36be3a4c418b97981b7c1 to your computer and use it in GitHub Desktop.
Wait for activating systemd mount units
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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