mirror of
https://github.com/teslamate-org/teslamate.git
synced 2026-01-24 21:06:08 +08:00
On certain systems (e.g., Debian 13 with modern container runtimes), a very high default `nofiles` ulimit can cause the Erlang VM (beam.smp) to pre-allocate excessive amounts of memory, leading to container crashes. This change introduces a safeguard directly into the entrypoint script: - It caps the soft `ulimit -n` to a configurable maximum, defined by the `ULIMIT_MAX_NOFILE` environment variable (defaults to 65536). - This behavior can be disabled by setting `ULIMIT_MAX_NOFILE=0`. - The new environment variable has been added to the documentation. To satisfy ShellCheck (SC3045), the script's shebang is set to `#!/usr/bin/env dash`, as `ulimit -n` is a common but not strictly POSIX-compliant extension.
24 lines
650 B
Bash
24 lines
650 B
Bash
#!/usr/bin/env dash
|
|
set -e
|
|
|
|
: "${DATABASE_HOST:="127.0.0.1"}"
|
|
: "${DATABASE_PORT:=5432}"
|
|
: "${ULIMIT_MAX_NOFILE:=65536}"
|
|
|
|
# prevent memory bloat in some misconfigured versions of Docker/containerd
|
|
# where the nofiles limit is very large. 0 means don't set it.
|
|
if test "${ULIMIT_MAX_NOFILE}" != 0 && test "$(ulimit -n)" -gt "${ULIMIT_MAX_NOFILE}"; then
|
|
ulimit -n "${ULIMIT_MAX_NOFILE}"
|
|
fi
|
|
|
|
# wait until Postgres is ready
|
|
while ! nc -z "${DATABASE_HOST}" "${DATABASE_PORT}" 2>/dev/null; do
|
|
echo waiting for postgres at "${DATABASE_HOST}":"${DATABASE_PORT}"
|
|
sleep 1s
|
|
done
|
|
|
|
# apply migrations
|
|
bin/teslamate eval "TeslaMate.Release.migrate"
|
|
|
|
exec "$@"
|