4

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


/systemd/system/service/foo@.service

[Unit]
Description=Foo service for %I

[Service]
User=keith
ExecStart=/path/to/foo/%i/food
...

/path/to/foo/bar/food

#/bin/bash

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.

ki9
  • 1,169
  • 1
  • 10
  • 18

2 Answers2

7

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
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
2

To complement the accepted answer, any file (including binaries) can be executed with substitution using /usr/bin/env:

ExecStart=/usr/bin/env /path/to/foo/%i/food