-
Sets up user linger and units: The script enables
lingerfor the current user so their user-level systemd instance can run without an active login, and installs theuser-network-online@.serviceunit at the system level plus anetwork-online.targetmarker unit in the user-level systemd directory. -
Bridges system network-online to user instance: The
user-network-online@.serviceruns as a system service afternetwork-online.target, and usessystemctl --user start network-online.target(with the appropriateXDG_RUNTIME_DIR) to trigger a correspondingnetwork-online.targetin the user’s systemd instance. -
Enables automatic startup on boot: By enabling
user-network-online@<UID>.servicewithsystemctl enable --now, the system ensures that whenever the system reachesmulti-user.targetand the network is online, the user-levelnetwork-online.targetis started automatically for that user.
Last active
December 10, 2025 12:29
-
-
Save aont/d999b9ca6962fc7f588a3d3e30bd29e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| loginctl enable-linger $USER | |
| sudo cp -t /etc/systemd/system/ user-network-online@.service | |
| sudo systemctl daemon-reload | |
| USER_SYSTEMD_PATH="$HOME"/.config/systemd/user | |
| mkdir -p "$USER_SYSTEMD_PATH" | |
| cp -t "$USER_SYSTEMD_PATH" network-online.target | |
| systemctl --user daemon-reload | |
| sudo systemctl enable --now user-network-online@$(id -u).service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Unit] | |
| Description=User-level Network is Online (marker only) | |
| Documentation=man:systemd.special(7) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Unit] | |
| Description=Trigger user-level network-online.target for %i | |
| After=network-online.target | |
| Wants=network-online.target | |
| [Service] | |
| Type=oneshot | |
| User=%i | |
| Environment=XDG_RUNTIME_DIR=/run/user/%i | |
| ExecStart=/usr/bin/systemctl --user start network-online.target | |
| [Install] | |
| WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment