segfault/sfbin/wait_semaphore.sh
2022-08-02 11:07:05 +01:00

26 lines
516 B
Bash
Executable File

#! /bin/bash
# EXIT unless "$2" exists.
#
# This is used by Nginx and sf-host to wait until EncFS
# has fully mounted the encrypted drives.
trap "exit 255" SIGTERM
sem="$1"
shift 1
[[ ! -f "${sem}" ]] && echo "Waiting for Semaphore '${sem}' before starting '$*'"
n=0
while :; do
[[ -n $SF_DEBUG ]] && echo "Round #${n}"
[[ -e "${sem}" ]] && { echo "Found after #${n} rounds..."; exec "$@"; }
n=$((n+1))
[[ $n -gt 10 ]] && break
sleep 1
done
echo "Semaphore '${sem}' does not yet exist. Exiting."
exit 123