2

I am trying to create a new systemd unit template file that will be used to start several instances of a server program, each running out of a different directory. i.e. I need the ExecStart parameter to be different depending on the instance.

I have tried making the path to the instance be the instance name like the following. I have the following unit file /etc/systemd/system/myserver@.service:

[Unit]
Description=server instance '%I'
Requires=...
Wants=...

[Service]
Type=simple
ExecStart=%I/bin/server.sh
PIDFile=%I/server.pid

[Install]
WantedBy=multi-user.target

I do a daemon-reload:

$ sudo systemctl daemon-reload

And I try to start an instance with:

$ sudo systemctl start myserver@/path/to/instance1.service

I get an error from this saying look at the status for details. So, I do:

$ sudo systemctl status myserver@/path/to/instance1.service

I see an error that the ExecStart path is not absolute:

May 17 16:04:46 myhost systemd[1]: [/etc/systemd/system/myserver@.service:9] \
  Executable path is not absolute, ignoring: %I/bin/server.sh
May 17 16:04:46 myhost systemd[1]: tistfe@-path-to-instance1.service lacks \
  both ExecStart= and ExecStop= setting. Refusing.

Is there a way to parameterize the path to the ExecStart binary (and PIDFile)? Am I stuck making a separate unit file for every instance?

  • Don't use a pathname as the instance name. – Michael Hampton May 18 '16 at 4:59
  • Yes, I gathered that doesn't work from my experiment. – John L May 24 '16 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.