• Difference between xxx.service and xxx@user.service in systemd

    From Chris Green@3:633/10 to All on Thursday, January 29, 2026 20:10:01
    I am a bit confused by systemd user services.

    I have two service files in ~/.config/systemd/user/ as follows:-

    -rw-rw-r-- 1 chris chris 184 Jan 29 18:14 fblcd@chris.service
    -rw-rw-r-- 1 chris chris 178 Jan 27 21:32 helmlcd.service

    They are very similar, helmlcd.service is:-

    [Unit]
    Description=Run the helm display

    [Service]
    Type=simple
    StandardOutput=journal
    ExecStart=/home/chris/bin/helmlcd.py
    Restart=on-failure

    [Install]
    WantedBy=default.target

    The differences in fblcd@chris.service are just the description and
    the executable file:-

    [Unit]
    Description=Run the Flying Bridge display

    [Service]
    Type=simple
    StandardOutput=journal
    ExecStart=/home/chris/bin/fblcd.py
    Restart=on-failure

    [Install]
    WantedBy=default.target


    Both are installed and run (using systemctl) in the same way, so
    what's the difference between them? What does the @chris do, if
    anything?

    These are both written by me so they may very likely be misconfigured
    in some way. :-) They are running on a headless system and I want
    them to run when the system is [re]booted. They run continuously
    displaying electrical values on two LCD displays.

    --
    Chris Green
    ú

    --- PyGate Linux v1.5.6
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Andy Smith@3:633/10 to All on Thursday, January 29, 2026 21:00:01
    Hi,

    On Thu, Jan 29, 2026 at 06:35:19PM +0000, Chris Green wrote:
    I am a bit confused by systemd user services.

    Just FYI the "user" part here is a bit redundant as what you're asking
    about is templated services, which is a general concept that also
    applies to system services.

    I have two service files in ~/.config/systemd/user/ as follows:-

    -rw-rw-r-- 1 chris chris 184 Jan 29 18:14 fblcd@chris.service
    -rw-rw-r-- 1 chris chris 178 Jan 27 21:32 helmlcd.service

    The first is a templated service while the second isn't. Templated
    services allow the same service unit to be used multiple times as
    different "instances" of the same service. In your case you have an
    instance named "chris".

    The differences in fblcd@chris.service are just the description and
    the executable file:-

    [Unit]
    Description=Run the Flying Bridge display

    [Service]
    Type=simple
    StandardOutput=journal
    ExecStart=/home/chris/bin/fblcd.py
    Restart=on-failure

    [Install]
    WantedBy=default.target

    Normally a templated service makes use of the instance by the specifier
    "%i" somewhere in the unit file, often the ExecStart like, e.g. to set a command-line option or load a specific config. Yours doesn't, so it may
    be just an arbitrary string to allow multiple of these to be run at
    once. Or maybe systemd also sets something in the environment and /home/chris/bin/fblcd.py is reading that. I am not familiar with that
    script.

    Both are installed and run (using systemctl) in the same way, so
    what's the difference between them? What does the @chris do, if
    anything?

    It's an identifier that allows multiple instances of the "fblcd" service
    to run at the same time.

    If you only use one instance and never make use of the string expansion
    then it has no effect.

    These are both written by me so they may very likely be misconfigured
    in some way. :-) They are running on a headless system and I want
    them to run when the system is [re]booted. They run continuously
    displaying electrical values on two LCD displays.

    Is there a reason you chose to use '@chris' in the service file name
    without knowing what it does?

    Thanks,
    Andy

    --
    https://bitfolk.com/ -- No-nonsense VPS hosting

    --- PyGate Linux v1.5.6
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris Green@3:633/10 to All on Thursday, January 29, 2026 22:00:01
    Andy Smith <andy@strugglers.net> wrote:
    [long, helpful, explanation snipped]


    If you only use one instance and never make use of the string expansion
    then it has no effect.

    These are both written by me so they may very likely be misconfigured
    in some way. :-) They are running on a headless system and I want
    them to run when the system is [re]booted. They run continuously displaying electrical values on two LCD displays.

    Is there a reason you chose to use '@chris' in the service file name
    without knowing what it does?

    Presumably I copied it from somewhere when I first created the script.

    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.

    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.

    How does the second differ from simply having services called chrisfblcd.service, othernamefblcd.service and so on?

    --
    Chris Green
    ú

    --- PyGate Linux v1.5.6
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Andy Smith@3:633/10 to All on Thursday, January 29, 2026 22:50:01
    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

    --
    https://bitfolk.com/ -- No-nonsense VPS hosting

    --- PyGate Linux v1.5.6
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris Green@3:633/10 to All on Friday, January 30, 2026 10:10:02
    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
    ú

    --- PyGate Linux v1.5.6
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)