entrypoint.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. appHooks() {
  3. : ${APP_RELINK:=false}
  4. if [ "$APP_RELINK" = "true" ]; then
  5. [ ! -z "${APP_CONF}" ] && relink_dir "${APP_CONF_DEFAULT}" "${APP_CONF}"
  6. [ ! -z "${APP_DATA}" ] && relink_dir "${APP_DATA_DEFAULT}" "${APP_DATA}"
  7. [ ! -z "${APP_LOGS}" ] && relink_dir "${APP_LOGS_DEFAULT}" "${APP_LOGS}"
  8. [ ! -z "${APP_TEMP}" ] && relink_dir "${APP_TEMP_DEFAULT}" "${APP_TEMP}"
  9. [ ! -z "${APP_WORK}" ] && relink_dir "${APP_WORK_DEFAULT}" "${APP_WORK}"
  10. [ ! -z "${APP_SHARED}" ] && relink_dir "${APP_SHARED_DEFAULT}" "${APP_SHARED}"
  11. else
  12. echo "=> Skipping APP directories relinking: APP_RELINK=$APP_RELINK"
  13. fi
  14. echo "=> Executing hooks:"
  15. . /entrypoint-hooks.sh
  16. echo "-------------------------------------------------------------------------------"
  17. }
  18. relink_dir() {
  19. local dir_default="$1"
  20. local dir_custom="$2"
  21. [ ! -e "$dir_default" ] && mkdir -p "$dir_default"
  22. [ ! -e "$(dirname "$dir_custom")" ] && mkdir -p "$(dirname "$dir_custom")"
  23. echo "Directory container override detected! default: $dir_default custom: $dir_custom"
  24. if [ ! -e "$dir_custom" ]; then
  25. echo -e -n "=> moving the $dir_default directory to $dir_custom ..."
  26. mv "$dir_default" "$dir_custom"
  27. else
  28. echo -e -n "=> directory $dir_custom already exist... "
  29. mv "$dir_default" "$dir_default".dist
  30. fi
  31. echo "linking $dir_custom into $dir_default"
  32. ln -s "$dir_custom" "$dir_default"
  33. }
  34. appHooks
  35. : ${APP_RUNAS:=false}
  36. : ${ENTRYPOINT_TINI:=false}
  37. : ${MULTISERVICE:=false}
  38. if [ "$MULTISERVICE" = "true" ]; then
  39. CMD="runsvdir -P /etc/service"
  40. elif [ "$APP_RUNAS" = "true" ]; then
  41. CMD="runuser -p -u $APP_USR -- $@"
  42. else
  43. CMD="$@"
  44. fi
  45. [ "$ENTRYPOINT_TINI" = "true" ] && CMD="tini -g -- $CMD"
  46. echo "=> Executing entrypoint command: $CMD"
  47. echo "==============================================================================="
  48. [ ! -z "$UMASK" ] && umask $UMASK
  49. set -x
  50. exec $CMD
  51. exit $?