Is there a way of setting a service name dynamically in a service file?
I am running several instances of a service, where all services uses different input arguments. For debugging this is not optimal as all services are called the same and it can be tedious finding out which service is actually complaining. So what I want is to give the service a unique name for a given input. Systemds service files support this by changing the arg[0] in ExecStart
by setting the prefix "@" where the second argument will be the arg[0] value.
Information about ExecStart
command and the @ prefix:
https://www.freedesktop.org/software/systemd/man/systemd.service.html
So this is what I have so far in my service file:
ExecStart=@/usr/bin/foo foo-%I %I
The input argument is a file, so it will be called something like bar-123.json. This works and the service name will be foo-bar-123.json when I use top, ps or the QA tools we are using. The input files are created by another service that also starts the "foo" service instance using systemctl dbus api.
However having the service called foo-bar-123.json is not the best and instead I would like to call is foo-bar.
I have tried running, as a test:
**ExecStartPre=/bin/sh -c 'export NAME=bar'**
**ExecStart=@/usr/bin/foo foo-${NAME} %I**
But then the name will be "foo-". Am guessing this is to be expected as the service file is not a shell script, however that was the only solution I could think of.
Other solution to the problem are also welcomed. I know that PR_SET_NAME in the prctl function should also change the name of the process but I am not sure who they relates to each other. The reason I don't want to use the prctl function is that is says that the name only can be 16 bytes long including the null byte, this is a limitation that I would be nice not to have.