HeadlinesBriefing favicon HeadlinesBriefing.com

Bridging systemd network-online.target to user instances

DEV Community •
×

When a Linux system boots, the systemd framework waits for the network-online.target before launching services. Modern developers, however, run long‑lived daemons inside a user instance of systemd, which normally starts only after a login. A lightweight bridge solves this mismatch by installing a small install.sh script, a user‑level marker unit, and a templated system service that triggers the user target once the system reports the network is ready.

Enabling linger with `loginctl enable-linger $USER` keeps the user systemd daemon alive even when no session is active, allowing services to start during boot. The marker unit, a minimal network-online.target, contains no networking logic; it simply acts as a synchronization flag. User services can then declare `After=network-online.target` and `Wants=network-online.target` to enforce order.

The system‑level template [email protected] waits for the system’s network-online.target, then runs `systemctl --user start network-online.target` with `XDG_RUNTIME_DIR=/run/user/%i`. This environment variable points the command to the correct runtime directory, ensuring the user target starts even without an active session. Once triggered, all user services that depend on the marker begin automatically at boot.