2

I'm familiar with creating ordinary systemd services. However, when learning how to configure wireguard, I came across the '@' symbol in service names and was wondering exactly how it works.

For example, in wireguard, you can configure a connection in /etc/wireguard/wg0.conf and then control that connection as if it had it's own service file by running sudo systemctl [enable|disable|start|stop|whatever] wg-quick@wg0.service. If you create a second config file called wg1.conf, you can control it via the wg-quick@wg1.service.

this is all very handy, but how does it work? what is it called?

2
  • Relating: unix.stackexchange.com/q/588629/315749 - about systemd instance units in general, does not address the specific WireGuar case.
    – fra-san
    Nov 27, 2022 at 14:01
  • 1
    man systemd.unit, look for "template file"
    – Panki
    Nov 27, 2022 at 14:02

1 Answer 1

4

@ symbols in SystemD services are used to create services that take a variable so as you can have multiple of the same service with different configs/targets.

So in this case it allows you to distinguish between configurations, but it's used by many other things such as ceph to allow you to run multiple of the same service but serving up different resources.

Basically when you create your systemd service file you can use %i and it will substitute in whatever comes after the @ symbol.

So you could create a oneshot service that just echos whatever is after the @ like this

[Unit]
Description=Echo '%I'

[Service]
Type=oneshot
ExecStart=/bin/echo %i
StandardOutput=syslog

And anything you put after the @ would be put in syslog.

Hope that helps!

4
  • 1
    You explained %i, but in the code you used %i and %I. Are they equivalent? Nov 27, 2022 at 23:35
  • 1
    @KamilMaciorowski - Isn't it just a description? Note that the Echo is also capitalised, with a E rather than a e. Maybe the capitalisation is used to differentiate the description from the actual command. Even so, it is a bit misleading, I must admit. Nov 27, 2022 at 23:46
  • 1
    @Greenonline It is a description and I want to know why it's not Echo '%i'. I know a description can be almost anything, but is there a technical reason to use %I or not to use %i? Nov 27, 2022 at 23:51
  • 1
    @KamilMaciorowski Just read the manual systemd.unit(5). The lower case %i has its special characters escaped.
    – yt7b97q-
    Nov 28, 2022 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.