webstation-broker
Container

Inside the image

How docker-webstation installs the broker, templates and runs nginx, and starts the broker as an s6 service.

This page is for anyone maintaining the image or debugging a container that won't start. Nothing here needs configuring in normal use.

How the broker gets in

The Dockerfile's runtime stage (the final stage of the image build) installs the broker from a GitHub release tarball. That's the source code archive GitHub generates automatically for every release, so nobody has to manually attach a file to a release for the image to use it:

ARG BROKER_RELEASE
# ...
  echo "**** install broker ****" && \
  mkdir -p /tmp/broker && \
  if [ -z ${BROKER_RELEASE+x} ]; then \
    BROKER_RELEASE=$(curl -sX GET "https://api.github.com/repos/romm-streaming/romm-broker/releases/latest" \
    | jq -er '.tag_name'); \
  fi && \
  curl -o \
    /tmp/broker.tar.gz -L \
    "https://github.com/romm-streaming/romm-broker/archive/${BROKER_RELEASE}.tar.gz" && \
  tar xf \
    /tmp/broker.tar.gz -C \
    /tmp/broker/ --strip-components=1 && \
  pip install /tmp/broker --break-system-packages && \
  cd /tmp/broker/frontend && \
  npm install && \
  SUBFOLDER=/streaming/ npm run build && \
  mkdir -p /usr/share/webstation-broker && \
  cp -r dist /usr/share/webstation-broker/www

Three things fall out of that:

  • The Python package is installed system-wide with pip (Python's package manager), which registers the webstation-broker console script the service runs.
  • The frontend (the room's web page) is built once, when the image is built, with SUBFOLDER=/streaming/ baked into it by vite, the tool that builds the page's files. Outside dev mode, the broker serves those built files as static files from BROKER_FRONTEND_DIST (default /usr/share/webstation-broker/www). You can still change SUBFOLDER afterward for the API and nginx, but the built page keeps whatever prefix it was built with. To use a different prefix, rebuild the image, or use dev mode, where vite serves the page live instead of from a pre-built copy.
  • BROKER_RELEASE pins the tag. If it's not set, the build uses the latest GitHub release. linuxserver's pipeline sets it to whatever release it found (more on that below), so every published image corresponds to exactly one tag, and the version pip records inside the image matches it.

How a release reaches the image

docker-webstation's romm branch is configured with external_type: github_stable, pointed at romm-streaming/romm-broker. A scheduled GitHub Actions workflow (external_trigger_scheduler.yml) runs and does the following:

  1. Reads the latest release tag from the broker's GitHub releases.
  2. Reads the build_version label off the currently published ghcr.io/linuxserver/webstation:romm manifest.
  3. If the two differ, and no build is already running, it starts the Jenkins pipeline, which builds the image with BROKER_RELEASE set to the new tag and publishes it.

So publishing a broker release (see Releases) is all it takes for a new image to appear. There's no manual step on the image side. The pipeline also regenerates the image's own README.md and package_versions.txt.

Boot sequence

The image is built on baseimage-selkies. From selkies 2.3.0 on, the base runs selkies as the session's compositor and window manager (its built-in WM, with Xwayland on :0 and the Wayland socket wayland-0), plus the bundled PulseAudio. It no longer ships nginx, labwc or openbox, so the romm branch installs nginx itself and adds three s6 units (s6 is the process supervisor linuxserver images use to start and manage services):

init-romm-config

Runs after init-selkies-config and before init-selkies-end. It owns everything nginx needs, since the base no longer sets nginx up:

NGINX_CONFIG=/etc/nginx/sites-available/default
CPORT="${CUSTOM_PORT:-3000}"
CHPORT="${CUSTOM_HTTPS_PORT:-3001}"
CWS="${CUSTOM_WS_PORT:-8082}"

# ensure master token is set
if [ -z "${SELKIES_MASTER_TOKEN}" ]; then
  SELKIES_MASTER_TOKEN=$(openssl rand -hex 24)
  echo "[ls.io-init] Generated SELKIES_MASTER_TOKEN for this boot"
fi
printf "%s" "${SELKIES_MASTER_TOKEN}" > /run/s6/container_environment/SELKIES_MASTER_TOKEN

# handle subfolder pathing
SFOLDER="${SUBFOLDER:-/streaming/}"
SFOLDER="/${SFOLDER#/}"
SFOLDER="${SFOLDER%/}/"
printf "%s" "${SFOLDER}stream/" > /run/s6/container_environment/SELKIES_SUBFOLDER
printf "%s" "http://127.0.0.1:${CWS}${SFOLDER}stream" > /run/s6/container_environment/SELKIES_CONTROL_URL

# nginx owns the public ports, svc-selkies reads these for its own listeners
printf "127.0.0.1" > /run/s6/container_environment/SELKIES_ADDR
printf "%s" "${CWS}" > /run/s6/container_environment/CUSTOM_PORT
printf "0" > /run/s6/container_environment/CUSTOM_HTTPS_PORT

# self-signed cert in /config/ssl (first boot only), then the nginx config
cp /defaults/default.conf ${NGINX_CONFIG}
sed -i -e "s/3000/${CPORT}/g" -e "s/3001/${CHPORT}/g" -e "s/CWS/${CWS}/g" \
  -e "s|SUBFOLDER|${SFOLDER}|g" ${NGINX_CONFIG}
# DISABLE_IPV6 strips the [::] listeners; PASSWORD writes /etc/nginx/.htpasswd
# and turns on basic auth for CUSTOM_USER (default abc)

# modify nginx ports for broker
if [[ "${BROKER_DEV_MODE,,}" == "true" ]]; then
  sed -i "s/BROKERWEB/5173/g" ${NGINX_CONFIG}
else
  sed -i "s/BROKERWEB/8000/g" ${NGINX_CONFIG}
fi

(Abridged; the full script also generates the certificate and handles DISABLE_IPV6 and PASSWORD.)

  • SELKIES_MASTER_TOKEN is the bearer token the broker uses to authenticate when it pushes token maps to selkies. It's generated fresh each boot unless you set it yourself, and it's shared with both services through the container environment so they always agree on the same value.
  • selkies listens only on 127.0.0.1:8082 (CUSTOM_WS_PORT), under SUBFOLDER + stream/, with no HTTPS listener of its own. nginx owns the public ports 3000 and 3001. SELKIES_CONTROL_URL is the base address the broker uses to reach selkies, both for status checks and for pushing token maps. The broker tries <control url>/api/tokens first, then /tokens, and remembers whichever one worked for next time.
  • The broker uses <control url>/api/session (selkies 2.3.0 and later) to switch between the desktop and a single app. Without that route, it starts selkies-desktop itself. Players can make the same switch from the right-click menu (SELKIES_SESSION_SWITCH, on by default), and the broker switches back to a single app between sessions.
  • The nginx template's BROKERWEB placeholder is filled in with whichever port serves the room page: 8000 in normal mode (uvicorn, the web server that runs the broker, serving the built frontend) or 5173 in dev mode (the vite dev server).

svc-nginx

Starts after init-services and runs nginx -g 'daemon off;' in the foreground, after clearing any nginx workers a previous run left behind.

The session environment

selkies writes the environment it starts the session's apps in to $XDG_RUNTIME_DIR/selkies-session-env.json (/config/.XDG by default). When selkies has the session mode API, the broker launches every emulator with its own environment plus whatever that file adds:

  • DISPLAY and WAYLAND_DISPLAY come from the file, falling back to :0 and wayland-0 when it names none. The broker's own inherited values are never used.
  • LD_PRELOAD is merged rather than replaced: the file's entries (selkies' input interposer, the fake libudev that gamepads depend on, v4l2) come first, then any the broker carries. The fake libudev no longer replaces the system libudev.so.1, so it only works through this preload.
  • Secret-shaped variables are stripped from both sides.

Without the session mode API the file is ignored, since it persists on the config volume and can be stale.

svc-broker

This service starts after init-services and svc-selkies. It waits for selkies to answer, then either runs the installed broker command, or, in dev mode, installs the mounted source code and runs uvicorn and vite with auto-reload instead:

echo "[svc-broker] waiting for selkies control plane at ${SELKIES_CONTROL_URL}"
until curl -sf -o /dev/null "${SELKIES_CONTROL_URL}/api/status"; do
  sleep 1
done

if [[ "${BROKER_DEV_MODE,,}" == "true" ]]; then
  pip install -e /broker --break-system-packages
  cd /broker/frontend
  s6-setuidgid abc npm install
  s6-setuidgid abc npm run dev -- --host 127.0.0.1 --port 5173 &
  cd /broker
  exec s6-setuidgid abc \
    uvicorn --factory webstation_broker.app:create_app \
      --host 127.0.0.1 --port 8000 \
      --reload --reload-dir /broker/webstation_broker
else
  exec s6-setuidgid abc webstation-broker
fi

The broker runs as the abc user, using whatever PUID and PGID you set. That's the same user the desktop and the emulators run as, so everything under /config has one owner. When it starts, the broker also cleans up any emulator process a previous broker left running, using the pid record at BROKER_PID_FILE.

nginx layout

/defaults/default.conf is nginx's config template. init-romm-config copies it to /etc/nginx/sites-available/default at boot and fills SUBFOLDER into it, and it serves everything under that one prefix, on port 3000 (HTTP). It also listens on port 3001 (HTTPS, self-signed), which you can ignore: use port 3000 only.

LocationUpstreamPurpose
SUBFOLDER + stream/selkies on 127.0.0.1:8082 (CUSTOM_WS_PORT)the selkies web client (compiled into the selkies binary), the stream websocket and the control API, unlimited body size
SUBFOLDER + api/broker on 8000the REST API, 512 MB body limit for state files and save archives
SUBFOLDER + ws/broker on 8000the collab room websocket
SUBFOLDERBROKERWEB (8000 or 5173)the room page and its assets

Every proxied location forwards the Host, X-Forwarded-For and X-Forwarded-Proto headers. That's what lets activate work out the callback origin from the incoming request. Websocket locations also carry the upgrade headers and hour-long timeouts, so an idle session doesn't get disconnected.

Files the broker writes under /config

PathWhat
/config/broker-emulator.jsonpid record of the running emulator (BROKER_PID_FILE)
/config/broker-exports/save archives exit could not upload, or every archive in dev mode (BROKER_EXPORT_DIR)
/config/broker-imports/save archives uploaded through the import route, ready for activate (BROKER_IMPORT_DIR)
/config/<emulator>.logeach launcher's captured stdout and stderr, *_LOG_PATH
/config/.XDG/pcsx2.sockthe PINE socket the PCSX2 launcher drives

On this page