![]() |
Set ENV variable at startup
I have a 10.5 server (standard 10.5) 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?
I tried adding the variable to /etc/launchd.conf but it does not work. The file is only run when I log into a user account, which I don't want to do. Oddly, this is an extremely simple thing to do in Linux, but seems to be impossible in OSX. |
1) What user account runs the "webapp" that you are asking about?
Why can't you set the env var in the shell setup files for that account? Or in the setup for whatever program runs that app - e.g. the web server. 2) See also the last part of the section on env vars in this Unix FAQ |
First, this server is running Apache, so I guess user is www. I want a systemwide variable so I can invoke the script from ssh in additon to webpages.
Second, the ~/.MacOSX/environment.plist file only loads when the user has logged in, and I am running this machine headlessly (it stops booting at the login window). I can log in to the server ssh and see a whole list of environment variables, soI know it is possible somehow to set them. I should also explain that I spent several hours yesterday searching for the solution. |
1) See the Apache doc on setting env vars: http://httpd.apache.org/docs/2.2/env.html
2) When you use 'ssh', you are logging into a user account and hence the shell setup files for that account determine the environment. 3) You said that you tried setting the env var in "/etc/launchd.conf" but that it didn't work. That is surprising since the man pages indicate that this is the recommended mechanism and google shows others having had success with this: http://www.google.com/search?q=launchd.conf+setenv See for example: http://www.karma.net/html/index.php?...52144856072197 How exactly did you try to set the env var in launchd.conf ? Note that the contents of launchd.conf should be commands of the form expected by 'launchctl' - see the man page: http://developer.apple.com/documenta...unchctl.1.html And of course you need to reboot to see the effect of changes. |
1) Apache may be launching the shell script, so internal Apache variables are not relevant.
2) I could set the variable from the bash profile, but it would be limited to that Terminal session. 3) Yes, it is confusing. I did set it up on the home (dev) computer and it worked as expected. But the exact same file and permissions on my server do not load. Unless I have logged into a (any) user account. Maybe it is a bug in launchd, because I thought launchd was the precursor of all processes. |
Quote:
Quote:
Quote:
It's strange that it worked on your non-server machine but not on your server machine. Maybe this is a bug that affects only the OS X Server version of 'launchd' ? That seems strange since I don't imagine there is a difference in 'launchd' between OS X Server and OS X (client). |
My server is running standard OSX (which I might add works wonderfully serving 5 websites). It is running the exact same OS as my home computer. The only difference is that the server stops booting at the login screen.
It must be a bug in the OS. |
Quote:
Hence there must be something different about your server machine setup that is causing the difference. Have you checked the log files to see if there is anything relevant there? |
A user on another forum has verified that launchd.conf is not loaded UNTIL a user has logged in. So I am out of luck. This despite numerous UNIX experts insisting that launchd.conf is loaded at boot time. Wonder why Apple goes off in these nonstandard directions.
|
Quote:
http://developer.apple.com/documenta...5736-TPXREF104 Quote:
|
Quote:
And didn't you already say that it does work on your home machine? Quote:
-- George Bernard Shaw I.e. 'launchd' is a better way - and Apple hopes it will become standard. (It's open source.) |
Quote:
|
Has anybody here actually tried putting a 'setenv' statement in the "/private/etc/launchd.conf" file? Other than the OP, that is...
|
Quote:
I created the file /etc/launchd.conf using 'sudo vi' and inserted one 'setenv' line : Code:
% cat /etc/launchd.conf Code:
env | grep CECICode:
ConsoleMessage "CECI_NEST_PAS_UNE_PIPE=$CECI_NEST_PAS_UNE_PIPE"Code:
Aug 11 23:14:21 silverbook com.apple.SystemStarter[17]: CECI_NEST_PAS_UNE_PIPE=cigar |
I can duplicate Hayne's results, if not his mastery of French. I set up an /etc/launchd.conf that said setenv troubador wilco, and then wrote a launch daemon (placed in /Library/LaunchDaemons) which called a script that wrote 'wilco' to disk with a timestamp before my user login.
|
I want to thank you guys for all for your effort, but I am still not seeing the result I want. I log into my server as root and still don't get the variable I want. I have no doubt that StartupItems is reading the variable, but it is not accessible to root account via ssh. I suppose I could set the server to login to the GUI as root, but it would be rather insecure. And I shouldn't need to do it just to get an env variable.
|
Quote:
And even though you "have no doubt that StartupItems is reading the variable", it would be useful to test this by putting a "ConsoleMessage" to echo the value of the variable in whatever StartupItems script you are referring to. But do tell us in full detail what you are doing, including showing us the results of 'cat /etc/launchd.conf' and 'ls -ld /etc' |
I've not used ssh much, but I came across this thread that seems to be trying to resolve some of the same issues as this thread, I think. Maybe some of the solutions will help?
|
Quote:
If you login as root directy using ssh then why are you worried about logging in as root on the GUI? |
Thanks for all the help, I have solved this problem expediently but not elegantly. Rather than use the same shell env var I have configured Apache to duplicate the value and will access it from the script. I still do not know how to set a shell var that user www can access.
|
Quote:
|
| All times are GMT -5. The time now is 05:32 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.