Running systemd user units on boot
November 28th, 2022
I have a home server that runs Linux, using cloudflaredd to update my DNS records dynamically. Since my home server does have a few users (@sharaelong uses my home server to host his website), I prefer to run code related to my own domain scoped to my own user.
Since I’d like to update my records even if I’m not logged in, I thought that user systemd unit would be impossible.
Turns out that’s not the case; according to ArchWiki, one can
turn on lingering via loginctl enable-linger <username>
, and the
systemd user instance will start up on boot. Units wanted by the
target default.target
will be automatically started.
My final ~/.config/systemd/user/cloudflaredd.service
file looks like
this:
[Unit]
Description=Cloudflare DDNS
After=network.target
[Service]
Type=simple
ExecStart=/home/sungbin/.local/bin/cloudflaredd
Restart=always
[Install]
WantedBy=default.target