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


Description=Foo service for %I




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

Then I run:

$ sudo systemctl daemon-reload
$ sudo systemctl start foo@bar
$ sudo systemctl status foo@bar
‚óŹ foo@bar.service - Foo service for bar
   Loaded: loaded (/etc/systemd/system/foo@.service; 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]: foo@bar.service: Main process exited, code=exited, status=203/EXEC
Sep 30 19:07:02 kptow systemd[1]: foo@bar.service: Unit entered failed state.
Sep 30 19:07:02 kptow systemd[1]: foo@bar.service: 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 answer on Server Fault.

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