Set ENV variable at startup

I have a 10.5 server that boots up to the login window. How would I set an environment variable that will be accessible to the shell for a Python webapp?

2.4 MBP, Mac OS X (10.5.7)

Posted on Aug 7, 2009 7:21 AM

Reply
11 replies

Aug 7, 2009 3:13 PM in response to Gnarlodious

Apparently the file is not loaded until a GUI starts up. So it does not work on my server.


Not so. /etc/launchd.conf should be loaded first at boot time.

launchd is responsible for the entire boot process - launching all background tasks and services. As such it has to read its configuration file at boot.

Now it is possible for an individual to have their own launchd.plist file that is loaded when they log in, but that would have to be stored in their home directory, not in /etc/

Did you check permissions on the file? Or the logs?

It wouldn't surprise me to find that launchd won't load the file if it's world-writable since that could constitute a security violation (you don't want just anyone adding entries to this file). That could explain why it didn't load at boot.

Aug 7, 2009 4:11 PM in response to Camelot

OK, so I can log into the GUI with Remote Desktop and I get the variable in Terminal. Both in root and a user account. However, still no variable in ssh.

So I think you are wrong.

After much Googling and reading pages that say it is inordinately difficult to do what I want to do (in OSX), I am starting to agree. Ironically, this is about the simplest thing to do on any Linux box.

Aug 7, 2009 4:08 PM in response to Camelot

Camelot wrote:
Edit /etc/launchd.plist


that should be /etc/launchd.conf not /etc/launchd.plist, I think.
(or create it if it doesn't exist) and add a line:

setenv YOUR ENVVARIABLE /some/value


This file is read by launchd when the system boots and any environment variables set there are available for all processes.

Aug 8, 2009 6:34 PM in response to Gnarlodious

Gnarlodious wrote:
> Not so. /etc/launchd.conf should be loaded first at boot time.


If that is true, the only explanation is that it must be a bug.

I tested it and it does indeed work as you say. when I ssh into a computer, variables set in /etc/launchd.conf are not loaded. I don't know enough about these things to judge if it's a bug or if that's how it should be (I suspect the latter). but in any case if you need some variables to load when you ssh you can just add them to the global shell configuration files. for example, if you ssh into an account whose login shell is bash, add the following line to /etc/.profile


export YOURENVVARIABLE=some-value


if you need to you can do the corresponding things for global configuration files for other shells. the syntax will vary depending on the shell of course.

I strongly suspect there is a better way to do this but the above should work.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Set ENV variable at startup

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.