You are not logged in.

#1 2016-07-07 01:53:10

thePhysicist8
Member
Registered: 2015-06-25
Posts: 17

[SOLVED] Best way to set the executable path in a systemd service file

I should probably preface this by saying that I'm not a developer.

I'm writing a script that will include a few systemd service files, which I understand require absolute paths to their respective executables. Because I don't know where the user will choose to install the program, I don't know the absolute paths of these executables. I don't want to just assume that they'll be using the /usr/local/ prefix. The only solution that I could come up with would involve an install script that modifies the unit files accordingly, although I was planning on using a makefile to install the program. Is there a best practice regarding how to set ExecStart= in the service files?

Also: Where should I install the unit files? Let's say the user chooses to install in /usr/local/. Should they go in /usr/local/lib/systemd/user/ or /usr/lib/systemd/user/? I know that systemd checks /usr/local/lib/systemd/user/ for unit files, but it may not check wherever else they choose to install to, making /usr/lib/ a safer bet. I'm hesitant to install them under /usr/lib/, however, because I thought that hierarchy was reserved for use with a package manager.

Last edited by thePhysicist8 (2016-07-08 12:38:14)

Offline

#2 2016-07-07 08:41:11

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,302

Re: [SOLVED] Best way to set the executable path in a systemd service file

man systemd.exec:

ENVIRONMENT VARIABLES IN SPAWNED PROCESSES
       Processes started by the system are executed in a clean environment in which select variables listed below are set. System processes started by systemd do not inherit variables
       from PID 1, but processes started by user systemd instances inherit all environment variables from the user systemd instance.

       $PATH
           Colon-separated list of directories to use when launching executables. Systemd uses a fixed value of /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.

Is this what you are looking for?
It's not clear what you try to do...

Offline

#3 2016-07-07 12:41:07

thePhysicist8
Member
Registered: 2015-06-25
Posts: 17

Re: [SOLVED] Best way to set the executable path in a systemd service file

That's not what I was looking for. Maybe I did a poor job of explaining it the first time.

I understand that processes spawned by the service inherit environment variables like $PATH, but I'm not talking about those processes. I'm talking about calling an executable from the ExecStart= line within the service file itself. While you can use environment variables (such as $PATH) within systemd unit files, that doesn't mean that they can interpret $PATH. Running ${PATH}/my-binary doesn't work in bash because $PATH is just a colon-separated list of directories, and the same goes for unit files. As far as I know, you must use an absolute path for ExecStart=. I'm wondering how I'm supposed to know what that absolute path is when I don't know where the executables are.

Last edited by thePhysicist8 (2016-07-07 12:44:01)

Offline

#4 2016-07-07 14:46:57

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED] Best way to set the executable path in a systemd service file

Configure the service file in your Makefile.

sed 's/@BINDIR@/$(BINDIR)/g' myscript.service.in > myscript.service

Last edited by eschwartz (2016-07-07 14:48:26)


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

Board footer

Powered by FluxBB