Re: Difference between xxx.service and xxx@user.service in systemd
Andy Smith <andy@strugglers.net> wrote:
> Hi,
>
> On Thu, Jan 29, 2026 at 08:28:47PM +0000, Chris Green wrote:
> > So, if I understand correctly, when I do:-
> >
> > systemctl --user start helmlcd.service
> >
> > Then, although it has been started by 'chris' (I'm logged in as
> > chris), only one copy of the service can be run.
>
> Only one copy by user chris, yes. It's not a templated service. If you
> want multiple of them running as user services of chris then you'd have
> to copy the .service file to a new name, making the copy effectively a
> completely separate and different service.
>
> As it's a user service, it's expected that a DIFFERENT user could also
> run it.
>
> > However, when I do:-
> >
> > systemctl --user start fblcd@chris.service
> >
> > it's quite possible for others to start their own copies of the
> > service, though presumably they'd have to have a copy of the service
> > file called fblcd@othername.service.
>
> As long as there is a fblcd@.service template file somewhere in
> systemd's search paths (for user units), then if a user does:
>
> myusername$ systemctl --user start fblcd@foo
>
> Then they should get their own instance of this service. It may be a
> requirement of the service that "foo" is actually the username, or it
> might not be, leaving it to just be an arbitrary instance name. As this
> is a templated user service there is in principle no reason why a single
> user can't run multiple instances of it. There might be some
> service-specific reason why each user can only run one.
>
> The "start" command with an instance name should copy the .service file
> from the template.
>
> > How does the second differ from simply having services called
> > chrisfblcd.service, othernamefblcd.service and so on?
>
> There only has to be one template unit file somewhere called
> fblcd@.service rather than every user having to copy their own one into
> place. Also the fact that it's a template indicates that it's expected
> that multiple copies of it are in some way catered for.
>
Thanks Andy, that's brilliant! :-)
--
Chris Green
·
Reply to: