LaunchDaemons and environment variables

For a while, I noticed that my Apache2 instance installed by MacPorts did not start at startup ( MacPorts Apache2 stopped starting at boot ). LaunchDaemon is loading. Today I came across something in a log file that might indicate an answer, but I cannot find confirmation.

I use environment variables in my httpd.conf file. In particular, the variable ${HOME} . Is it possible (or possible, etc.) for environment variables to be fully loaded when running LaunchDaemons? I can add them to the plist file, but I hope someone can provide me with a decent high level during the OS X boot process and confirm that I think I see.

Thanks.

+2
environment-variables osx-snow-leopard startup macos
source share
1 answer

I found this page about the MacOSX boot process , which contains some information. Basically, launchd starts and starts as root. Then each daemon starts launchd based on the plist file.

As for the environment during the start of the daemon, I did not find a single bit of explicit information. But after reading the launchctl man, I found a command that can print the launchd environment. 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 believe the print environment is used to run daemons. If you retry the operation without root transition, the environment should match the user environment.

0
source share

All Articles