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.
Thanks for your help
Harold
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#Environme...
Thank you very much. That did it!
Hal
-----Original Message----- From: CentOS centos-bounces@centos.org On Behalf Of Jonathan Billings Sent: Friday, October 23, 2020 1:06 PM To: CentOS mailing list centos@centos.org Subject: Re: [CentOS] Apache HTTPD not picking up environment variables.
[EXTERNAL SENDER - PROCEED CAUTIOUSLY]
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#Environme...
-- Jonathan Billings billings@negate.org _______________________________________________ CentOS mailing list CentOS@centos.org https://lists.centos.org/mailman/listinfo/centos