Files
jcoffey-dev 8388c97089
ci / node (pull_request) Skipped
ci / version (pull_request) Skipped
ci / docker-build (pull_request) Skipped
ci / publish (pull_request) Skipped
github/ci (branch) GitHub Actions
ci / github (pull_request) Successful in 1m43s
ci / announce (pull_request) Skipped
Drain on SIGTERM instead of dropping everything (K-W5)
On SIGTERM the server exited at once: a JMAP request in flight failed in
the browser, and a request reaching the pod as it went hung until it
timed out. Now it drains (server/src/drain.ts):

1. /api/health answers 503 and every response says Connection: close,
   so load balancers and keep-alive clients move to another replica;
   requests are still served, for SHUTDOWN_DELAY (3 s).
2. No new connections, and every live-update stream (fan-out, relay and
   raw relay) is ended cleanly, so each tab's EventSource reconnects to a
   replica that's staying.
3. Requests in flight get SHUTDOWN_TIMEOUT (5 s) to finish; then what's
   left is closed and the process exits. A second signal stops at once.

Tested in the lab (inbuxa-k8s-lab webmail-restart-test.sh): a rolling
restart under three open tabs and a JMAP request every 200 ms. The
released webmail had a request hang for 30 s; with this, 182-183
requests and none failed, three runs out of three, every stream ending
cleanly and reconnecting.
2026-11-20 00:23:27 -07:00

149 lines
6.8 KiB
Bash

# ---- ihasmail server configuration ----
# Base URL of your mail server (scheme + host, no path). ihasmail discovers
# the JMAP session at <MAIL_SERVER_URL>/.well-known/jmap.
MAIL_SERVER_URL=https://mail.example.com
# Random secret used to derive encryption keys for persisted sessions.
# Generate with: openssl rand -base64 48
# APP_SECRET, APP_SECRET_PREVIOUS and OAUTH_CLIENT_SECRET can each be read
# from a file instead: APP_SECRET_FILE=/run/secrets/app-secret (set one form,
# not both).
APP_SECRET=change-me
# Listen address. :: answers on IPv6 and IPv4 alike; 0.0.0.0 is IPv4 only.
HOST=::
PORT=8080
# Serve the app from a subpath instead of the domain root, for a reverse proxy
# that maps https://example.com/mail/ here. Leave it unset for the root, which
# is what every deployment gets unless it asks otherwise. "/mail", "mail" and
# "/mail/" all mean the same thing.
#
# The prefix must reach ihasmail intact -- do not strip it in the proxy -- and
# it has to be set for the *build* as well as the run: the web bundle writes
# its own asset URLs, so a build that does not know the prefix produces an app
# that cannot load itself under one. With Docker that means
# `--build-arg BASE_PATH=/mail` alongside `-e BASE_PATH=/mail`.
# BASE_PATH=/mail
# Set to "1" when running behind a TLS-terminating reverse proxy (trusts
# X-Forwarded-* and marks cookies Secure). Set to "0" for plain-HTTP dev.
TRUST_PROXY=1
# Peers whose X-Forwarded-* headers are believed. Unset means loopback and the
# private ranges, which covers a reverse proxy on the same host or Docker
# network. A request from anywhere else is attributed to its socket address,
# whatever the headers claim -- otherwise anyone could pick their own key for
# the login rate limiter.
# TRUSTED_PROXIES=10.0.0.0/8,192.168.1.5
SECURE_COOKIES=auto
# Session lifetime (idle timeout) in seconds. "Remember me" extends to SESSION_REMEMBER_TTL.
SESSION_TTL=43200
SESSION_REMEMBER_TTL=2592000
# Where to persist sessions so restarts don't log everyone out (optional).
# Leave it empty to hold sessions in memory only, which is what an immutable
# instance does -- see IMMUTABLE below.
SESSION_FILE=./data/sessions.json
# Where sessions live. "memory" (default) is the above: this process, mirrored
# to SESSION_FILE. "cookie" seals each session into its own cookie instead, so
# any replica can serve it and a restart signs nobody out -- what running more
# than one webmail replica (Kubernetes, say) needs. It requires APP_SECRET set
# to the same value on every replica, and OAuth sign-in (OAUTH_CLIENT_SECRET).
# The cost: the Security page can't list or sign out your other sessions;
# changing the password still signs out everywhere. Signing out revokes the
# session's tokens at the mail server, so a copy of the cookie stops working;
# that needs a server with token revocation (inbuxa-server 27.1 or later).
# Against an older one, a copied cookie works until its tokens expire, and a
# warning is logged at each sign-out. Use PUSH_MODE=relay with
# several replicas: subscribe mode fans out only to tabs on the replica the
# mail server calls back.
# SESSION_BACKEND=memory
# When rotating APP_SECRET in cookie mode: the old value(s), comma-separated.
# Cookies sealed with them still open and are re-sealed with the new secret
# on their next request. Drop them once SESSION_REMEMBER_TTL has passed.
# APP_SECRET_PREVIOUS=
# Assert that this instance is running as an immutable container: read-only
# root filesystem, no durable state of its own. It is checked rather than
# taken on trust -- the server refuses to start if SESSION_FILE is set, or if
# the filesystem it is installed on turns out to be writable. Off by default.
# Running one looks like:
# docker run --read-only --tmpfs /tmp -e IMMUTABLE=1 -e SESSION_FILE= ...
# In memory mode a restart signs everyone out, since there is nowhere left to
# keep the sessions; SESSION_BACKEND=cookie removes that cost.
# IMMUTABLE=1
# Upstream timeouts / limits
UPSTREAM_TIMEOUT=30000
# On SIGTERM (docker stop, a Kubernetes rollout) the server drains instead of
# dropping everything: it keeps serving for SHUTDOWN_DELAY ms while load
# balancers move on, then stops taking connections and ends each tab's
# live-update stream cleanly (the tab reconnects to another replica), and
# gives requests in flight SHUTDOWN_TIMEOUT ms to finish. The defaults fit
# inside docker stop's 10 s.
SHUTDOWN_DELAY=3000
SHUTDOWN_TIMEOUT=5000
MAX_UPLOAD_BYTES=52428800
# Remote-image privacy proxy (Gmail-style). Set to 0 to load remote images directly.
IMAGE_PROXY=1
# In-app administration, for accounts whose role on the mail server manages accounts and
# domains. 0 turns it off for everyone: no menu, and the JMAP proxy refuses
# the mail server's registry methods beyond an account's own password, app passwords
# and settings. INBUXA Admin is not affected.
ADMINISTRATION=1
# Branding
APP_NAME=ihasmail
# Where this instance's source can be had. ihasmail is AGPL-3.0-or-later, which
# asks whoever runs a modified version to offer *that* version's source -- so if
# you have patched it, point this at your own tree. Shown on the sign-in page
# and in Settings > About. INBUXA's webmail is itself a modified ihasmail, so
# the default is this fork.
SOURCE_URL=https://git.coffeylabs.org/inbuxa/inbuxa-webmail
# ---- Settings this installation decides (all optional) ----
#
# Seed what a new account starts on, lock what nobody may change, and turn
# something on once for accounts that already exist. Setting none of these --
# the default -- behaves exactly as ihasmail always has.
#
# A file is easier once there are `changes` in it. See the shipped
# settings-policy.example.json, and mount it read-only:
#
# -v /srv/ihasmail/policy.json:/etc/ihasmail/policy.json:ro
#
# SETTINGS_POLICY_FILE=/etc/ihasmail/policy.json
#
# Or inline, which is what an immutable deployment with no volume wants. These
# are ignored entirely when SETTINGS_POLICY_FILE is set, so a file and a stray
# variable cannot half-apply between them.
#
# SETTINGS_DEFAULTS={"externalSenderBanner":true}
# SETTINGS_ENFORCED={"externalRecipientConfirm":true}
# SETTINGS_CHANGES=[{"version":"20260902084513","settings":{"externalSenderBanner":true}}]
#
# Read once at startup: editing a policy means restarting the container.
# Docs: https://docs.ihasmail.org/configure/#settings-your-installation-decides
# ---- Several mail servers (optional) ----
#
# Choose the upstream by the domain someone signs in with. MAIL_SERVER_URL above
# stays required and stays the default; this only adds domains that go
# elsewhere. See the shipped mail-servers.example.json, and mount it
# read-only:
#
# -v /srv/ihasmail/servers.json:/etc/ihasmail/servers.json:ro
#
# MAIL_SERVERS_FILE=/etc/ihasmail/servers.json
#
# An unlisted domain, or a username with no domain, goes to MAIL_SERVER_URL. A
# listed domain never falls back. Read once at startup: editing means a restart.