entrypoint.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. # shellcheck disable=SC1091,SC1090
  3. set -e
  4. source /etc/s6-overlay/scripts/base.sh
  5. ARGS_FILE="/run/gpustack/args"
  6. mkdir -p "$(dirname "$ARGS_FILE")"
  7. # If any arguments are passed to the container, save them to the args file
  8. if [ "$#" -gt 0 ]; then
  9. echo "[INFO] Saving docker run args to $ARGS_FILE"
  10. : > "$ARGS_FILE"
  11. for arg in "$@"; do
  12. printf '%s\n' "$arg" >> "$ARGS_FILE"
  13. done
  14. else
  15. echo "[INFO] No docker run args passed."
  16. : > "$ARGS_FILE"
  17. fi
  18. # Check and ensure nofile ulimit is at least 65535
  19. REQUIRED_NOFILE=65535
  20. CURRENT_NOFILE=$(ulimit -n)
  21. if [ "$CURRENT_NOFILE" != "unlimited" ] && [ "$CURRENT_NOFILE" -lt "$REQUIRED_NOFILE" ]; then
  22. echo "[INFO] Current nofile ulimit ($CURRENT_NOFILE) is below required ($REQUIRED_NOFILE), attempting to increase..."
  23. if ! ulimit -n "$REQUIRED_NOFILE" 2>/dev/null; then
  24. echo "[WARN] Failed to set nofile ulimit to $REQUIRED_NOFILE. Current value: $CURRENT_NOFILE."
  25. echo "[WARN] To fix this, try the following:"
  26. echo "[WARN] 1. Run the container with: --ulimit nofile=${REQUIRED_NOFILE}:${REQUIRED_NOFILE}"
  27. echo "[WARN] 2. If that still fails, check the host kernel limit: sysctl fs.nr_open"
  28. echo "[WARN] and raise it if needed: sysctl -w fs.nr_open=1048576"
  29. else
  30. echo "[INFO] nofile ulimit set to $(ulimit -n)."
  31. fi
  32. fi
  33. # remove generated gateway config to force regeneration
  34. rm -rf "${GPUSTACK_GATEWAY_CONFIG}"
  35. export S6_STAGE2_HOOK="/etc/s6-overlay/scripts/gpustack-prerun.sh"
  36. exec /init "$@"