entrypoint.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env bash
  2. if [[ -z "$CONTAINER_UID" ]]; then
  3. export CONTAINER_UID="application"
  4. fi
  5. set -o pipefail # trace ERR through pipes
  6. set -o errtrace # trace ERR through 'time command' and other functions
  7. set -o nounset ## set -u : exit the script if you try to use an uninitialised variable
  8. set -o errexit ## set -e : exit the script if any statement returns a non-true return value
  9. # auto elevate privileges (if container is not started as root)
  10. if [[ "$UID" -ne 0 ]]; then
  11. export CONTAINER_UID="$UID"
  12. exec gosu root "$0" "$@"
  13. fi
  14. # remove suid bit on gosu
  15. chmod -s /sbin/gosu
  16. trap 'echo sigterm ; exit' SIGTERM
  17. trap 'echo sigkill ; exit' SIGKILL
  18. # sanitize input and set task
  19. TASK="$(echo $1| sed 's/[^-_a-zA-Z0-9]*//g')"
  20. source /opt/docker/bin/config.sh
  21. createDockerStdoutStderr
  22. if [[ "$UID" -eq 0 ]]; then
  23. # Only run provision if user is root
  24. if [ "$TASK" == "supervisord" -o "$TASK" == "noop" ]; then
  25. # Visible provisioning
  26. runProvisionEntrypoint
  27. else
  28. # Hidden provisioning
  29. runProvisionEntrypoint > /dev/null
  30. fi
  31. fi
  32. #############################
  33. ## COMMAND
  34. #############################
  35. runEntrypoints "$@"