systemd instance name (%i) not working in ExecStart

Keith asked:

For some reason, systemd is not replacing %i or %I with the instance name in ExecStart

/systemd/system/service/[email protected]

Description=Foo service for %I




node /path/to/foo/bar/bard.js

Then I run:

$ sudo systemctl daemon-reload
$ sudo systemctl start [email protected]
$ sudo systemctl status [email protected]
‚óŹ [email protected] - Foo service for bar
   Loaded: loaded (/etc/systemd/system/[email protected]; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2016-09-30 19:07:02 EDT; 6s ago
  Process: 18705 ExecStart=/path/to/foo/%i/food (code=exited, status=203/EXEC)
 Main PID: 18705 (code=exited, status=203/EXEC)

Sep 30 19:07:02 kptow systemd[1]: Started Foo service for bar.
Sep 30 19:07:02 kptow systemd[1]: [email protected]: Main process exited, code=exited, status=203/EXEC
Sep 30 19:07:02 kptow systemd[1]: [email protected]: Unit entered failed state.
Sep 30 19:07:02 kptow systemd[1]: [email protected]: Failed with result 'exit-code'.

The %I in the description gets replaced, but the %i in the ExecStart doesn’t. I’ve tried using %i/%I, but neither works.

My answer:

The first argument to ExecStart= must be an absolute path to an executable. Substitutions are not accepted.

If you’re just loading a bash script which then starts Node.js, you can do that explicitly:

ExecStart=/bin/bash /path/to/foo/%i/food

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.