0

I am having OpenRC start a service that calls a java jar, but the PATH it uses appears to either be different than the global PATH, or the service is ran before the PATH can be edited.

I have tried adding java to the PATH in

  • \etc.profile.d script
  • \etc\profile
  • \etc\bash\bashrc

But logging the PATH in the service always seems to show it to be the default:

PATH=/bin:/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

The depend() in the .service file:

depend() {
    after sshd
    after docker
}
Koops128
  • 111

1 Answers1

0

All three configuration files you've mentioned are for interactive shells – they are loaded when a user logs in on a terminal. But services, almost by definition, start entirely outside the "user login" environment and will never pay attention to that kind of shell configuration.

There is no such thing as "global PATH", like any other environment variable it is actually process-specific – any changes only affect that particular process subtree. For example, if you set PATH in one shell window, the change will only be visible to programs started from that particular window – not even to your own other programs. So because /etc/profile is only read by interactive login shells, it will only have effect on interactive logins; the changes do not propagate "upwards".

(In other words, it doesn't really matter that your service runs "after sshd" or "after user login" – the timeline is not linear in the first place, it's a tree where the service has already diverged from your sshd logins.)

From what I could find out, in OpenRC you can set service-specific environment variables by editing /etc/conf.d/<service>, which is a shell script using the same syntax as /etc/profile (i.e. you need to use the same export VAR=value syntax).

grawity
  • 501,077