[systemd-devel] How to set complex environment for apache?
Sven Anders
anders at anduras.de
Thu May 24 00:44:49 PDT 2012
Am 24.05.2012 01:56, schrieb Lennart Poettering:
> On Wed, 23.05.12 16:45, Joachim Banzhaf (joachim.banzhaf at googlemail.com) wrote:
>
>> Am 22.05.2012 22:51, schrieb Zbigniew Jędrzejewski-Szmek:
>>> On 05/22/2012 10:46 PM, Joachim Banzhaf wrote:
>>>> It sets and modifies environment variables. I'll have a look and try,
>>> See also Environment= and EnvironmentFile= in systemd.exec(5).
>>>
>>> Zbyszek
>>
>> I tried now. Not sure if the result is optimal, but it might still help
>> others with a similar problem.
>>
>> The DB2 provided profile script (for now) only sets and changes
>> environment variables (PATH, LD_LIBRARY_PATH, CLASSPATH, DB2INSTANCE),
>> with some if/else logic based on what product options are installed or not.
>>
>> I cannot use the script as is in ExecStartPre because this only allows
>> binaries.
>> I even tried /bin/bash script, but as expected the changed environment
>> is not inherited by ExecStart
>>
>> So the only systemd options (I know of now) left are Environment and
>> EnvironmentFile.
>> I went with EnvironmentFile, because that is what I used before. I just
>> added the variables by hand instead of by sourcing the db2profile
>> script. This worked (I had to export the variables to make it backward
>> compatible with SysV init though).
>>
>> If I'd use this approach with systemd and DB2 I'd have to manually
>> analyze changes in the db2profile and try to mimic that with every
>> fixpack or special build delivered by IBM. Too error prone, not acceptable.
>>
>> Finally I tried this, and it worked. But I am not sure about side effects:
>>
>> I changed
>> ExecStart=/usr/sbin/start_apache2 -D SYSTEMD -k start'
>> to
>> ExecStart=/bin/bash -c '. /home/db2inst1/sqllib/db2profile;
>> /usr/sbin/start_apache2 -D SYSTEMD -k start'
>>
>> Thanks for you support!
>
> This solution is pretty much what I'd recommend too.
Would adding an "exec" allow to get rid of the bash?
Will this have any advantages?
ExecStart=/bin/bash -c '. /home/db2inst1/sqllib/db2profile; exec /usr/sbin/start_apache2 -D SYSTEMD -k start'
For some cases it would be nice if you could run an command to set complex environments.
Something like:
EnvironmentExec=/home/db2inst1/sqllib/db2profile
But instead of just reading the file, it's executed and the environment variables are taken.
Another idea I had was to have the possibility to set single variables which can be used in
the Exec command by executing external commands. But I think this would made systemd too complex...
Regards
Sven Anders
--
Sven Anders <anders at anduras.de> () UTF-8 Ribbon Campaign
/\ Support plain text e-mail
ANDURAS intranet security AG
Messestrasse 3 - 94036 Passau - Germany
Web: www.anduras.de - Tel: +49 (0)851-4 90 50-0 - Fax: +49 (0)851-4 90 50-55
Those who would give up essential Liberty, to purchase a little
temporary Safety, deserve neither Liberty nor Safety.
- Benjamin Franklin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: anders.vcf
Type: text/x-vcard
Size: 352 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20120524/f5b5a369/attachment.vcf>
More information about the systemd-devel
mailing list