UlfR
UlfR

Reputation: 4395

How can I enable unit templates?

I have written a my own unit template:

/etc/systemd/user/[email protected]

This is the base for a bunch of services I want to come up at boot. I do want to create each service as a symlink to the template something like this:

$ cd /etc/systemd/user
$ sudo ln -s [email protected] [email protected]
$ sudo ln -s [email protected] [email protected]
...

But if I now try to enable the services I get:

$ sudo systemctl enable [email protected]
Failed to execute operation: Too many levels of symbolic links

To solve this I copied the file instead:

$ cd /etc/systemd/user
$ sudo cp [email protected] [email protected]
$ sudo cp [email protected] [email protected]
...

Now systemctl enable works as expected.

But: Making all those copies and keeping them synced when the template is changed are awkward and sort of defeats the purpose of a templating system I think.

What am I missing here? Could the runners be enabled without copying the template?

I'm using Ubuntu 16.04 and systemd=229


Btw: If I after enabling of the service replace it with a symlink it will still work for some systemctl commands (daemon-reload, start, stop and status) while is-enabled, enable and disable will all fail with:

Failed to execute operation: Too many levels of symbolic links

Strange I think, and I have not tried to reboot my system to see if that works...

Upvotes: 2

Views: 3295

Answers (1)

papey
papey

Reputation: 4134

You don't need symlinks. Just use

systemctl start/enable [email protected]. Then, systemd will use your template directly.

See https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers for more info about specifiers (ie, variables you can use inside you template)

If you want more, paste template and expected result.

Upvotes: 2

Related Questions