segfault/sfbin/wait_semaphore.sh

26 lines
516 B
Bash
Raw Normal View History

2022-08-01 17:26:57 +00:00
#! /bin/bash
# EXIT unless "$2" exists.
#
2022-08-02 10:07:05 +00:00
# This is used by Nginx and sf-host to wait until EncFS
# has fully mounted the encrypted drives.
2022-08-01 17:26:57 +00:00
trap "exit 255" SIGTERM
sem="$1"
shift 1
2022-08-02 10:07:05 +00:00
[[ ! -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."
2022-08-01 17:26:57 +00:00
exit 123