1.6 KiB · text History a2252b9
#!/bin/sh
# Sourced by every `bin/waxx <command>` invocation. We always set
# `RELEASE_NODE` when `POD_IP` is available because *every* subcommand
# needs to know the running release's node name:
#
#   - `start` / `daemon`  register the running server under this name.
#   - `remote` / `eval` / `rpc`  pass it to `-remsh` (or RPC dial) to
#     attach to the running server. The temporary BEAM those commands
#     spawn picks its OWN unique short name (`rem-<rand>@<host>`),
#     so setting RELEASE_NODE here does not cause an epmd collision —
#     it only tells the temporary BEAM which target to talk to.
#
# Only `start` / `daemon` get the dist port pinned, since the
# temporary BEAMs for remote/eval/rpc only make outbound connections
# and don't need their own listener at a known port.
#
# POD_IP comes from the deployment's downward API. RELEASE_COOKIE
# comes from the waxx-secrets Secret so every replica agrees on the
# Erlang cookie.

if [ -n "${POD_IP:-}" ]; then
  export RELEASE_DISTRIBUTION=name
  export RELEASE_NODE="waxx@${POD_IP}"
else
  echo "[env.sh] POD_IP is empty — falling back to default short-name distribution" >&2
fi

case ${RELEASE_COMMAND:-} in
  start*|daemon*)
    echo "[env.sh] starting with name distribution as ${RELEASE_NODE:-(unset)}" >&2
    # Pin the inet_dist listener so the port is predictable from peers
    # and matches the headless service / any future NetworkPolicy.
    # Without this BEAM picks a random ephemeral port each boot.
    export ELIXIR_ERL_OPTIONS="${ELIXIR_ERL_OPTIONS:-} -kernel inet_dist_listen_min 9100 inet_dist_listen_max 9100"
    ;;
esac