Bug 965537 - Can not find the database related environment variables if without stop and start the app after adding the cartridges
Can not find the database related environment variables if without stop and s...
Product: OpenShift Online
Classification: Red Hat
Component: Containers (Show other bugs)
Unspecified Unspecified
medium Severity medium
: ---
: ---
Assigned To: Jhon Honce
libra bugs
: FutureFeature
: 965680 (view as bug list)
Depends On:
  Show dependency treegraph
Reported: 2013-05-21 06:42 EDT by congqiyuan
Modified: 2015-05-14 19:19 EDT (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2013-07-01 11:26:01 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description congqiyuan 2013-05-21 06:42:47 EDT
Description of problem:
Description of problem:
Given a Perl-5.10 embeded with mongodb-2.2 and 10gen-mms-agent-0.1, it fails to load "OPENSHIFT_10GENMMSAGENT_IDENT" and "OPENSHIFT_10GENMMSAGENT_DIR" env vars from its web page.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. create a Perl-5.10 application as app1
2. add mongodb-2.2 to the app
3. cd into the app'repo/.openshift and mkdir mms
4. cd into mms and create a settings.py 
5. in the app'repo/perl, create a new page named universal.pl with the following code:


#!/usr/bin/env perl
use URI::Escape;
print "Content-type: text/plain\r\n\r\n";

# Get parameters in query string
my $param = {};
if(length($ENV{'QUERY_STRING'}) > 0) {
    $buffer = $ENV{'QUERY_STRING'};
    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs){
        ($name, $value) = split(/=/, $pair);
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
        $param{$name} = uri_unescape($value);

if(not exists($param{'group'})) {
    print "Usage: $ENV{'OPENSHIFT_APP_DNS'}/universal.pl?group=<group>\nValid groups are 'shell', 'env'\n";
    exit 255

# Try to load OPENSHIFT env vars with shell commands passed in HTTP request
if($param{'group'} eq "shell") {
    if(not exists($param{'cmd'})) {
        print "Usage: $ENV{'OPENSHIFT_APP_DNS'}/universal.pl?group=shell&cmd=<shell command>\n";
        exit 1
    my $cmd = $param{'cmd'};
    print "Command: $cmd\n";
    my $output = `$cmd`;
    print "Exit value: $?\n";
    print "===================================Output=====================================\n";
    print $output;
    print "==============================================================================\n";

# Load all server side env vars
elsif($param{'group'} eq "env") {
    print "The env vars of $ENV{'OPENSHIFT_APP_NAME'}\n";
    foreach $key(keys %ENV){
        print "$key=$ENV{$key}\n";


6.git push all the changes
7.add cartridge  10gen-mms-agent-0.1 to the app
8. Try to load all env vars of this app via visiting
9. Try to load  env vars of  10gen-mms-agent-0.1  via visiting
<app_url>/universal.pl?group=shell&cmd=env | grep OPENSHIFT_10GENMMSAGENT_IDENT
<app_url>/universal.pl?group=shell&cmd=env | grep OPENSHIFT_10GENMMSAGENT_DIR

Actual results:
Exit value: 256

Exit value: 256

Expected results:

Additional info:
Comment 1 Jhon Honce 2013-05-21 15:17:18 EDT
*** Bug 965680 has been marked as a duplicate of this bug. ***
Comment 2 Jhon Honce 2013-05-21 18:55:58 EDT
Fixed in https://github.com/openshift/origin-server/pull/2580
Comment 3 openshift-github-bot 2013-05-21 21:59:25 EDT
Commit pushed to master at https://github.com/openshift/li

Bug 965537 - Dynamically build PassEnv httpd configuration

* Update httpd configuration on each start and restart
Comment 4 openshift-github-bot 2013-05-21 21:59:28 EDT
Commit pushed to master at https://github.com/openshift/origin-server

Bug 965537 - Dynamically build PassEnv httpd configuration

* Update httpd configuration on each start and restart
Comment 5 congqiyuan 2013-05-22 04:28:43 EDT
the bug failed on devenv_3258 again

the result is 
Exit value: 256
Exit value: 256
Comment 6 Meng Bo 2013-05-22 04:31:57 EDT
Checked on devenv_3258,

After a restart of the app, the new added env_vars still cannot be found by the code.

Assign the bug back.
Comment 7 Meng Bo 2013-05-22 05:47:01 EDT
The PR https://github.com/openshift/origin-server/pull/2580 seems did not fix the issue.

For all the apache based app, it cannot read the db cartridge env_vars after added it, unless do a git push or a manually stop/start.

As it mentioned in Card: https://trello.com/card/pick-up-env-vars-for-apache-restart/50fc6bb487602f214b003f71/126
The env_vars should be reloaded after add/remove the cartridge or restart the app.
Comment 8 Jhon Honce 2013-05-22 13:28:42 EDT
Updated card to be clearer on actual results.

The httpd-based cartridges cannot update when another cartridge is added or removed without restarted the httpd-based cartridge. 

The new feature allows the httpd configuration to pick up any available cartridge environment variables when httpd is restarted, the environment variables are no longer hard coded in httpd.conf.
Comment 9 Meng Bo 2013-05-23 04:36:51 EDT
Checked on devenv_3262 again,

The httpd_nolog.conf will be updated after each restart, and OPENSHIFT env_vars will be written to the file.

But it still cannot be loaded by the code.

eg. PHP
# cat php/test.php 
    foreach ($_ENV as $key=>$val )
         echo $key."\n";

After restart the web cartridge, the test.php page dose not update accordingly.

1. Create php app
2. Add above code to check the env
3. Add mysql to the app
4. Restart the php cartridge 
5. Login to the app to check the httpd_nolog.conf file
The new mysql env_vars are imported to the file.
6. Refresh the page

It still cannot get the new envs.

And if stop the app and start it again, the new env_vars will be shown on the web page.
Comment 10 Xiaoli Tian 2013-05-23 04:58:21 EDT
It seems restart app will not cause the parent httpd pid change, for eg:

Before restart app, the parent httpd pid is 11592:

[phpapp-domx1.dev.rhcloud.com 866111267982399670059008]\> ps -ef|grep http
516      11592     1  0 04:34 ?        00:00:00 /usr/sbin/httpd -C Include /var/lib/openshift/866111267982399670059008/php//configuration/etc/conf.d/*.conf -f /var/lib/openshift/866111267982399670059008/php//configuration/etc/conf/httpd_nolog.conf -k start
516      27918 11592  0 04:45 ?        00:00:00 /usr/sbin/httpd -C Include /var/lib/openshift/866111267982399670059008/php//configuration/etc/conf.d/*.conf -f /var/lib/openshift/866111267982399670059008/php//configuration/etc/conf/httpd_nolog.conf -k start

[root@ip-10-196-90-40 ~]# rhc app restart phpapp
phpapp restarted

After restart the app, the parent httpd pid is still  11592

[phpapp-domx1.dev.rhcloud.com 866111267982399670059008]\> ps -ef|grep httpd
516      11592     1  0 04:34 ?        00:00:00 /usr/sbin/httpd -C Include /var/lib/openshift/866111267982399670059008/php//configuration/etc/conf.d/*.conf -f /var/lib/openshift/866111267982399670059008/php//configuration/etc/conf/httpd_nolog.conf -k start
516      14471 11592  0 04:53 ?        00:00:00 /usr/sbin/httpd -C Include /var/lib/openshift/866111267982399670059008/php//configuration/etc/conf.d/*.conf -f /var/lib/openshift/866111267982399670059008/php//configuration/etc/conf/httpd_nolog.conf -k start
Comment 11 Jhon Honce 2013-05-24 11:24:47 EDT
httpd restart signals httpd to read it's configuration. Having the same pid is as designed.
Comment 12 Jhon Honce 2013-05-28 18:56:14 EDT
The PHP framework does not support reading new variables on 'httpd restart', nor do any other frameworks with the exception of the Perl framework.

The Perl framework does support reading new variables on 'httpd restart'.
Comment 13 Meng Bo 2013-05-29 09:45:17 EDT
Tested against perl cartridge with script in the Comment#0

Still cannot get the new env_vars via rhc app restart and rhc cartridge restart.

Not sure if it is caused by Bug 968340

I can get the env updated after a ctl_all restart from the gear shell, but seems the ctl_all restart perform a stop and start actually.
Comment 14 Dan McPherson 2013-07-01 11:26:01 EDT
Closing as upstream and will be handled with:  https://trello.com/c/2A5mmrCG

Note You need to log in before you can comment on or make changes to this bug.