Re: Apache HTTPD not picking up environment variables.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Fri, Oct 23, 2020 at 04:27:34PM +0000, Harold Pritchett wrote:
> I'm trying to install DB2 on a CentOS 7 server.  The problem I'm
> seeing is that the Apache httpd server fails to pick up the db2
> environment variables.  On an older version running under CentOS 5
> this was done by inserting the following lines into the httpd start
> script in /etc/sysconfig/httpd: 
> 
> if test -f /db2home/db2inst1/sqllib/db2profile; then
>   . /db2home/db2inst1/sqllib/db2profile
> fi
> 
> Under CentOS 7's systemctl system this no longer works. I need a
> clue as to where to start looking for where to put this so it will
> be sourced when the Apache server starts.  I have googled this and
> can find nothing relevant.  I even did a "find / -name httpd -print"
> and didn't find anything looking promising. 

In non-systemd systems, httpd was started by a shell script
(/etc/rc.d/init.d/httpd) which sourced the file /etc/sysconfig/httpd,
so you could embed shell code in the file and it would be evaluated.

In systemd systems, the httpd.service unit has:

EnvironmentFile=/etc/sysconfig/httpd

For systemd units, setting this will cause the systemd unit to read in
the file for variables, but it ignores anything that isn't a simple
'foo=bar' syntax.  It doesn't evaluate shell scripts.


HOWEVER, the logic of your shell script is something that can be
supported by systemd units.  You can say:

EnvironmentFile=-/db2home/db2inst1/sqllib/db2profile

and it will only try to source that file for variables if it exists.

So, what you should do is create a directory and file within it
called:

/etc/systemd/system/httpd.service.d/override.conf

With these two lines in it:

[Service]
EnvironmentFile=-/db2home/db2inst1/sqllib/db2profile

Then run (as root) 'systemctl daemon-reload', and it should
conditionally load the environment variables on startup from that file
if the file exists.

This assumes that /db2home/db2inst1/sqllib/db2profile doesn't have
more shell syntax in it, of course.

See for more details:

https://www.freedesktop.org/software/systemd/man/systemd.exec.html#EnvironmentFile=



-- 
Jonathan Billings <billings@xxxxxxxxxx>
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
https://lists.centos.org/mailman/listinfo/centos



[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]


  Powered by Linux