2

To quote http://www.freedesktop.org/software/systemd/man/systemd.service.html#Command%lines:

The command line accepts "%" specifiers as described in systemd.unit(5). Note that the first argument of the command line (i.e. the program to execute) may not include specifiers.

I just ran into a use-case where I wanted to do this.

Why is this not possible? Is there a suggested workaround?

6
  • 1
    If you've run into this, I strongly suspect something is horribly wrong with your use case. Exactly what is it that you are trying to do? Feb 9, 2015 at 20:25
  • 1
    As to why, you should direct that at the systemd designers/developers.
    – user9517
    Feb 9, 2015 at 20:27
  • 1
    A workaround would be to have ExecStart call a script, pass it %i as a parameter, and have the script start the required binary.
    – larsks
    Feb 9, 2015 at 21:26
  • Yeah, I know it seems off. The problem is the daemon executable takes some of its config info relative to its full path (I know). That's why it's scattered all over the FS in different directories, and separate instances need to be run from separate directories. @larsks: that's what I'm doing right now, thanks.
    – maligree
    Feb 10, 2015 at 9:44
  • 1
    Why down vote? I think this is a perfectly fine question. The use case may be off (it annoys me a bit as well), but the question stands.
    – maligree
    Feb 10, 2015 at 9:48

2 Answers 2

3

According to the author himself (poettering) in this thread : it is forbiden because the executable name might be needed in advance (e.g.: SELinux needs this).

But according to other in the same thread and in that one, is still works sometime-ish.

Given that most specifiers can be determined statically in advance (template, machine, etc.) it should get supported eventually.

In the meantime, one solution is to launch a shell, as noted in the question comments and in the first thread:

ExecStart=/bin/sh -c "exec opt/%i/bin/service --args"

Another solution would be to manually invoke the ELF interpreter:

ExecStop=/lib64/ld-linux-x86-64.so.2 /usr/local/bin/%i-cli stop

(Basically the same idea as manually running /usr/bin/perl script.pl instead of trusting the she-bang of the script)

0
0

One way might be to use /usr/bin/env, then run the command after that as normal.

In my case, I wanted to write a non-absolute npm command:

ExecStart=/usr/bin/env npm start -- -p 2345

In your case you might do something like

ExecStart=/usr/bin/env some-command/%i/bin

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .