12

The idea is to use a variable pointing to node instead of hardcoded path, my solution was this ExecStart="$(which node)" /home/jonma/Development/chewy

But when I run the service I get the following error:

feb 08 11:12:51 jonma-VirtualBox systemd[1]: [/lib/systemd/system/chewy.service:2] Executable path is not absolute, ignoring: $(which node) /home/jon
feb 08 11:12:51 jonma-VirtualBox systemd[1]: chewy.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

How can I achieve this without hardcoding the path?

davejagoda
  • 2,420
  • 1
  • 20
  • 27
JonB
  • 804
  • 3
  • 12
  • 40
  • Related, see [Check if a program exists from a Bash script](https://stackoverflow.com/q/592620/608639). – jww Feb 08 '18 at 11:40

1 Answers1

18

systemd will not accept commands that are not given with absolute path, so to accomplish what you want you need rely on bash-ism and do one of the following:

ExecStart=/bin/bash -c '$$(which node) /home/jonma/Development/chewy'

or

ExecStart=/bin/bash -c '`which node` /home/jonma/Development/chewy'

(i like the first one better, but you can do any)

aleivag
  • 2,306
  • 1
  • 13
  • 13