From 3d9b7ef7712333d0f4c830980993debc74eeff40 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Sat, 9 May 2026 12:51:58 +0200 Subject: [PATCH] fix(deploy): WorkingDirectory= prefix `-` so ExecStartPre can mount the overlay systemd applies WorkingDirectory= to every Exec line including ExecStartPre. With the merged dir not yet existing at boot time (the volatile overlay mount has been wiped), the chdir into runtime/%i/merged/left4dead2 fails with status=200/CHDIR before ExecStartPre can run the mount helper. The `-` prefix makes chdir failure non-fatal: ExecStartPre runs in the unit's home (cwd doesn't matter for the mount helper); ExecStart re-applies WorkingDirectory once the mount has landed and chdirs successfully. Companion to commit 519567e (which added the ExecStartPre mount + helper idempotency but didn't account for the WorkingDirectory ordering). Co-Authored-By: Claude Opus 4.7 (1M context) --- .../usr/local/lib/systemd/system/left4me-server@.service | 7 ++++++- deploy/tests/test_deploy_artifacts.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/deploy/files/usr/local/lib/systemd/system/left4me-server@.service b/deploy/files/usr/local/lib/systemd/system/left4me-server@.service index 9031f79..7d987db 100644 --- a/deploy/files/usr/local/lib/systemd/system/left4me-server@.service +++ b/deploy/files/usr/local/lib/systemd/system/left4me-server@.service @@ -9,7 +9,12 @@ User=left4me Group=left4me EnvironmentFile=/etc/left4me/host.env EnvironmentFile=/var/lib/left4me/instances/%i/instance.env -WorkingDirectory=/var/lib/left4me/runtime/%i/merged/left4dead2 +# `-` prefix: chdir failure is non-fatal. systemd applies WorkingDirectory +# before every Exec line — including ExecStartPre — but the merged dir only +# exists once ExecStartPre's overlay mount succeeds. With `-`, ExecStartPre +# runs in the unit's home (cwd doesn't matter for the mount helper); the +# ExecStart re-applies WorkingDirectory after the mount and finds the dir. +WorkingDirectory=-/var/lib/left4me/runtime/%i/merged/left4dead2 # At boot the kernel-overlayfs mount is gone (mounts are volatile); the # web app's start_instance also pre-mounts but doesn't run on auto-start. # The helper is idempotent — a no-op if already mounted by the web app. diff --git a/deploy/tests/test_deploy_artifacts.py b/deploy/tests/test_deploy_artifacts.py index d0a307a..5f2057b 100644 --- a/deploy/tests/test_deploy_artifacts.py +++ b/deploy/tests/test_deploy_artifacts.py @@ -63,7 +63,10 @@ def test_server_unit_contains_required_runtime_contract(): assert "Group=left4me" in unit assert "EnvironmentFile=/etc/left4me/host.env" in unit assert "EnvironmentFile=/var/lib/left4me/instances/%i/instance.env" in unit - assert "WorkingDirectory=/var/lib/left4me/runtime/%i/merged/left4dead2" in unit + # `-` prefix: chdir failure is non-fatal so ExecStartPre can run the + # mount helper before the merged dir exists. ExecStart re-applies and + # finds the dir once the mount has landed. + assert "WorkingDirectory=-/var/lib/left4me/runtime/%i/merged/left4dead2" in unit assert "ExecStart=/var/lib/left4me/installation/srcds_run" in unit assert "$L4D2_ARGS" in unit assert "${L4D2_ARGS}" not in unit