systemd socket-activated service times out after moving /var to separate partition
Environment
Ubuntu 22.04 server running systemd 249 with /var moved to a dedicated ext4 LVM logical volume (fstab updated). A critical internal service uses systemd socket activation (mydaemon.socket → mydaemon.service).
Symptoms
After reboot the machine reaches multi-user.target but mydaemon never starts; systemctl status mydaemon shows 'loaded, inactive (dead)' and 'Socket unit mydaemon.socket is listening' with 'Startup finished in Xs (kernel)'. Attempts to start the service manually hang and eventually fail with a 90s timeout.
Observations
journalctl -b shows unit startup ordering: systemd starts mydaemon.socket before /var is mounted; logs include 'Failed to listen on socket: No such file or directory' pointing to /var/run/mydaemon.sock; fstab entry for /var uses UUID=... defaults, 0 2; 'systemctl list-dependencies multi-user.target' shows no explicit dependency from socket unit to local-fs.target; mounting /var manually and restarting the socket unit makes the service work immediately.
Already attempted
Edited mydaemon.service and mydaemon.socket to add After=local-fs.target and Wants=/var; reloaded systemd daemon and rebooted — no effect because the socket unit still activated too early. Tried adding x-systemd.automount to fstab for /var — caused different timing issues. Restored /var content to root filesystem (temporary) and service started normally.
Question
What is the minimal, reversible systemd unit or fstab change to ensure a socket‑activated service waits for /var to be mounted before systemd creates/listens on the socket? How can I avoid race conditions without moving /var back to the root filesystem?
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags