right way to set PATH for startup scripts

amarat

New Member


Messages: 4

I wonder is there a right way to set PATH environment variable for daemons we are starting via /usr/local/etc/rc.d/something startup scripts? each time I portupgrade apache I add the following line to /usr/local/etc/rc.d/apache:

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

and it would be great if there exists a way to set this PATH globally, and be sure that I don't forget to add this line to distribution startup script
 

phoenix

Administrator
Staff member
Administrator
Moderator

Reaction score: 1,259
Messages: 4,099

The global path is set in /etc/rc but you probably don't want to edit that directly, as it will be overwritten everytime you upgrade the OS. And you probably shouldn't be messing with the path for the system RC scripts. There are binaries installed under /usr/local/{sbin|bin} that have the same names as ones under /{sbin|bin} and /usr/{sbin|bin}.

Setting it in the individual script that needs it is a cleaner solution.

May I ask why the Apache RC script needs a different PATH?
 
OP
OP
A

amarat

New Member


Messages: 4

I know that messing with system-wide scripts is a bit of pain, so I'd rather prefer something like rc.conf variable, but, alas, there's no easy and elegant way to set machine-wide startup PATH, unfortunately. even login.conf doesn't work :(

setting a different path for apache and its children is my compatibility issue, I have some bad-formed code, that spawns processes by their short name and I haven't a chance to change this code.

Probably the question should be asked as: why user changed rc-script is deleted, while any other user-changed files are preserved?
 

Christopher

Member

Reaction score: 15
Messages: 57

Although I don't have an elegant solution to rc.d scripts needing a bigger $PATH than whats setup by /etc/rc, only a sloppy one of putting

Code:
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:
in /etc/rc.conf. Ugly.

I have ran into a similar problem with sloppy programmers calling binaries from web server scripts that are not in the default $PATH. I fixed that by the below shell code section.

Code:
mkdir -p /usr/local/etc/apache22/envvars.d/
echo 'export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:' > /usr/local/etc/apache22/envvars.d/path.env
chmod 755 /usr/local/etc/apache22/envvars.d/path.env
The rc.d script for apache22 is kind enough to execute /usr/local/sbin/envvars, which will then source ${ENVVARS_DIR}/*.env into the rc.d scripts' environment. Handy.
 
OP
OP
A

amarat

New Member


Messages: 4

I see. so, I'm doomed to make such changes every time I upgrade apache %) at least, while I'm bound to 1.3.x. Thanks phoenix, Christopher
 
Top