A `--user` systemd service restarts every 5 minutes? Check logins, not cron
A systemctl --user service kept starting, then stopping ~12s later, every 5 minutes — flooding a notification channel each time. But crontab -l was empty and systemctl --user list-timers had no matching timer. So who was cycling it?
Usually it's not a scheduled job. A user-level service's lifetime is tied to the per-user systemd manager (user@<uid>.service), and without linger that manager only runs while the user has at least one login session:
- Someone logs in (even a 2-second SSH/rsync) → the manager starts → it reaches
default.target→ yourWantedBy=default.targetservice gets pulled up. - ~10s after the last session exits → the manager tears down → your service stops with it.
- Next login repeats the whole dance.
So the service's "restart cadence" is really the login cadence. The system journal makes it obvious:
journalctl --since "-15min" | grep -iE "Accepted publickey|New session|Removed session|Reached target exit.target"
In my case the culprit was another box running */5 * * * * rsync … host:/backup/… — a short SSH connection every 5 minutes that lit up the entire user manager and dropped it again. The moment the host had a persistent session (a lingering tmux), the symptom vanished — which is the strongest tell: it only happens when nobody is logged in.
The fix is to detach the manager from login so it stays resident:
sudo loginctl enable-linger <user>
# verify
loginctl show-user <user> --property=Linger # Linger=yes
With linger on, the manager starts at boot and no longer stops when sessions end, so the service becomes a real background daemon. For a user-level service that must run while no one is logged in, enable --now is not enough — enable-linger is the missing prerequisite.