Skip to content

Instantly share code, notes, and snippets.

@sashaaro
Created November 1, 2019 13:02
Show Gist options
  • Save sashaaro/273a9e6e93a8c8aab2d1ee17174eab5e to your computer and use it in GitHub Desktop.
Save sashaaro/273a9e6e93a8c8aab2d1ee17174eab5e to your computer and use it in GitHub Desktop.
wait user existence
# wrap process and wait while required user would be created (for daemon ex. php-fpm) and others external init scripts would produced
# using USER=www-data wait-init.sh php-fpm
# test
# docker run --name=wait-init-test --rm -v $PWD/wait-init.sh:/wait-init.sh -e USER=www-data alpine sh wait-init.sh su -c "echo \"Dummy daemon started under \$(whoami)\"" www-data
# create user in container with some dockerhost id
# docker exec wait-init-test adduser -D --uid ${UID} www-data
# daemon required username
if [[ -z "${USER}" ]]; then
user="dockerhostuser"
else
user=$USER
fi;
echo "Waiting container init for user \"$user\"..."
while :
do
if id -u $user >/dev/null 2>&1; then
echo "Initialized container. Done!"
break;
else
sleep 3
fi
done
if [[ ! -z $@ ]]; then
echo "Run $@";
exec "$@";
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment