Skip to content

Commit

Permalink
fix: Startup script to set ulimit on proper user (#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecabaco committed May 22, 2024
1 parent 64159d6 commit 670071a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ COPY --from=tailscale /app/wrapper.sh /tailscale/wrapper.sh
COPY --from=tailscale /app/tailscaled /tailscale/tailscaled
COPY --from=tailscale /app/tailscale /tailscale/tailscale
RUN mkdir -p /var/run/tailscale /var/cache/tailscale /var/lib/tailscale

COPY limits.sh /app/limits.sh
ENTRYPOINT ["/usr/bin/tini", "-s", "-g", "--", "/tailscale/wrapper.sh"]

# Appended by flyctl
Expand Down
12 changes: 12 additions & 0 deletions limits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -euo pipefail

ulimit -n
if [ ! -z "$RLIMIT_NOFILE" ]; then
echo "Setting RLIMIT_NOFILE to ${RLIMIT_NOFILE}"
ulimit -Sn "$RLIMIT_NOFILE"
fi

echo "Starting Realtime in limits.sh"
ulimit -n
exec /app/bin/server
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Realtime.MixProject do
def project do
[
app: :realtime,
version: "2.29.1",
version: "2.29.2",
elixir: "~> 1.16.0",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down
12 changes: 4 additions & 8 deletions tailscale/wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if [ "${ENABLE_TAILSCALE-}" = true ]; then
/tailscale/tailscale up --authkey=${TAILSCALE_AUTHKEY} --hostname="${TAILSCALE_APP_NAME}" --accept-routes=true
fi

ulimit -n
export ERL_CRASH_DUMP=/tmp/erl_crash.dump

function upload_crash_dump_to_s3 {
Expand Down Expand Up @@ -63,16 +64,11 @@ fi

echo "Starting Realtime"

ulimit -n

if [ ! -z "$RLIMIT_NOFILE" ]; then
echo "Setting RLIMIT_NOFILE to ${RLIMIT_NOFILE}"
ulimit -Sn "$RLIMIT_NOFILE"
fi

if [ "${AWS_EXECUTION_ENV:=none}" = "AWS_ECS_FARGATE" ]; then
echo "Running migrations"
sudo -E -u nobody /app/bin/migrate
fi

sudo -E -u nobody /app/bin/server
ulimit -n

sudo -E -u nobody /app/limits.sh

0 comments on commit 670071a

Please sign in to comment.