3

I want to add some scripts for custom administrative work to a Linux server (Ubuntu 12.04). Ultimately those scripts are callback scripts from at least one daemon (PostgreSQL in my case but that shouldn't matter). In order for the daemon to find my script, I must provide the full path; I used /opt/<package>/bin as per the FHS.

When I add that path to PATH in /etc/environment, the user can call the script without providing the full path but the daemon can not; it just says "not found".

So my question is basically twofold:

  1. How do I add paths to PATH for daemons?
  2. Is it a good idea anyway? Or should I rather always use full path names?

2 Answers 2

3

When I add that path to PATH in /etc/environment, the user can call the script without providing the full path but the daemon can not; it just says "not found".

According to this source, which is IBM AIX documentation (I could not find anything else) but is presumably true in general:1

The first file that the operating system uses at login time is the /etc/environment file. The /etc/environment file contains variables specifying the basic environment for all processes.

Note that it is not sourced in any system wide .profile, so this is hard-coded somewhere. However, if it applies "at login time", it will not apply to a daemon, which is started by init and never logs in (although "for all processes" contradicts this, perhaps that was just a poor choice of words).

According to this superuser Q&A, /etc/environment is part of PAM, which supports the "at login" premise and again means it will not be used by init spawned daemons. There are a lot of other references for this too, but not, it seems, actual PAM documentation.

should I rather always use full path names?

This is the most common and generally recommended process -- it is possible for daemons to start with no $PATH at all. So you could set this yourself in a start-up script, or, as you say, use full path names as appropriate.

1. "/etc/environment" does not appear at all in what would seem to be the relevant POSIX specs [1] [2].

1
  • I guessed as much but it's nice to have some confirmation. I also wasn't aware that /etc/environment is part of PAM. Thanks.
    – musiKk
    Apr 7, 2014 at 19:41
1

This is very distribution dependent. /etc/environment belongs to PAM on Linux (as was pointed out already). However, /etc/environment is for logins, not for daemons. For services and daemons there are usually some configuration scripts that are sourced in (usually by some rc script), for instance these are found at /etc/conf.d/ with Gentoo Linux. But again, this is also very distribution dependent. Systemd for starting services is yet another story.

Better call programs by their absolute name - this is also security best practice as it avoids any ambiguity about which program is meant to run.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.