Bug 965537 - Can not find the database related environment variables if without stop and start the app after adding the cartridges
Summary: Can not find the database related environment variables if without stop and s...
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: OpenShift Online
Classification: Red Hat
Component: Containers
Version: 2.x
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
: ---
Assignee: Jhon Honce
QA Contact: libra bugs
URL:
Whiteboard:
: 965680 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-05-21 10:42 UTC by congqiyuan
Modified: 2015-05-14 23:19 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-07-01 15:26:01 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description congqiyuan 2013-05-21 10:42:47 UTC
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):
int

How reproducible:
always

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
<app_url>/universal.pl?group=env
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:
Command: env | grep OPENSHIFT_10GENMMSAGENT_DIR
Exit value: 256

Command: env | grep OPENSHIFT_10GENMMSAGENT_IDENT 
Exit value: 256

Expected results:
OPENSHIFT_10GENMMSAGENT_DIR
OPENSHIFT_10GENMMSAGENT_IDENT

Additional info:

Comment 1 Jhon Honce 2013-05-21 19:17:18 UTC
*** Bug 965680 has been marked as a duplicate of this bug. ***

Comment 2 Jhon Honce 2013-05-21 22:55:58 UTC
Fixed in https://github.com/openshift/origin-server/pull/2580

Comment 3 openshift-github-bot 2013-05-22 01:59:25 UTC
Commit pushed to master at https://github.com/openshift/li

https://github.com/openshift/li/commit/6c24aa44bdc77efc93fe5b1f34eca583a285c05d
Bug 965537 - Dynamically build PassEnv httpd configuration

* Update httpd configuration on each start and restart

Comment 4 openshift-github-bot 2013-05-22 01:59:28 UTC
Commit pushed to master at https://github.com/openshift/origin-server

https://github.com/openshift/origin-server/commit/373f718c3be39748b4136fb0cfcaba21c18127de
Bug 965537 - Dynamically build PassEnv httpd configuration

* Update httpd configuration on each start and restart

Comment 5 congqiyuan 2013-05-22 08:28:43 UTC
the bug failed on devenv_3258 again

the result is 
Command: env | grep OPENSHIFT_10GENMMSAGENT_IDENT
Exit value: 256
Command: env | grep OPENSHIFT_10GENMMSAGENT_DIR
Exit value: 256

Comment 6 Meng Bo 2013-05-22 08:31:57 UTC
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 09:47:01 UTC
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 17:28:42 UTC
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 08:36:51 UTC
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 
<?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 08:58:21 UTC
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
RESULT:
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 15:24:47 UTC
httpd restart signals httpd to read it's configuration. Having the same pid is as designed.

Comment 12 Jhon Honce 2013-05-28 22:56:14 UTC
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 13:45:17 UTC
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 15:26:01 UTC
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.