views:

232

answers:

1

For a while now, I've been noticing that my MacPorts-installed Apache2 instance hasn't been starting when I start up (http://stackoverflow.com/questions/2042992/macports-apache2-stopped-launching-on-boot). The LaunchDaemon is loaded. Today I bumped into something in a log file that may point to an answer, but I can't find any confirmation.

I use environment variables in my httpd.conf file. Specifically, the ${HOME} variable. Is it possible (or probable, etc.) that environmental variables are fully loaded when LaunchDaemons are executed? I can add them to the plist file, but I'm hoping someone can provide me with a decent, high level look into the boot process of OS X and confirm what I think I'm seeing.

Thanks.

A: 

I found this page about the Boot Process on MacOSX, which contains some information. Basically, launchd is started and run as root. Every daemons is then started by launchd based on the plist file.

Regarding the environment during daemon start, I have not find a single bit of explicit information. But after reading the launchctl man, I found a command that can print out the environment of launchd. So the trick is to go root and ask:

#$> sudo su
Password:
#$> whoami
root
#$> launchctl
launchd% export
PATH="/usr/bin:/bin:/usr/sbin:/sbin"; export PATH;
launchd% exit
#$> exit

I infer that the print environment is the one used when daemons are started. If you repeat the operation without going root, the environment must match the user's one.

Laurent Etiemble
Great information, thanks. I found similar info yesterday and the short version seems to be that the ${HOME} directory has no real meaning at launch. At least not the meaning I need/want it to have.
Rob Wilkerson
Yep, I guess you will have to put your environment into the plist.
Laurent Etiemble
So I added a value to my `environment.plist` file, but in order to prevent conflicts, I decided to try setting a custom variable named `HTTPD_CONF_BASE_PATH`. That seemed like a good idea, but Apache doesn't seem to like my custom value. It errors saying that `<path/to/my/httpd.conf>/${HTTPD_CONF_BASE_PATH}/includes` doesn't exist.
Rob Wilkerson