rickhumphries / bc-devdocs

Log issues here for processes involved in the NDP site audit
https://bc-docs.co.uk/sites/b-hive-developer-documentation
0 stars 0 forks source link

Config Errors on course site #1

Open rickhumphries opened 5 years ago

rickhumphries commented 5 years ago

On a course site, seeing multiple config errors like this:

Notice: Undefined index: elmslncfg in include() (line 57 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 57 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 57 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 58 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 58 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 59 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 59 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 59 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 60 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 60 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 61 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 61 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 61 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 62 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 62 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 63 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 63 of /var/www/elmsln/config/stacks/courses/sites/sites.php).
Notice: Undefined index: elmslncfg in include() (line 63 of /var/www/elmsln/config/stacks/courses/sites/sites.php).

This seems to be linked to the following in the $sites array:

$GLOBALS['elmslncfg']['serviceprefix'] . 'courses.' . $GLOBALS['elmslncfg']['serviceaddress'] . '.l2scifdn' => 'courses/services/' . $GLOBALS['elmslncfg']['host'] . '/l2scifdn',
'courses.' . $GLOBALS['elmslncfg']['address'] . '.l2scifdn' => 'courses/' . $GLOBALS['elmslncfg']['host'] . '/l2scifdn',

whereas those that look like this are OK:

'data.courses.buttercupstraining.co.uk.da' => 'courses/services/bc/da', 
'courses.buttercupstraining.co.uk.da' => 'courses/bc/da',
rickhumphries commented 5 years ago

The course sites that are registered in the first format also throws a HTTP 500 Error when trying to access it

rickhumphries commented 5 years ago

I did a quick test and switched the reference to the fluvac course in sites.php from:

$GLOBALS['elmslncfg']['serviceprefix'] . 'courses.' . $GLOBALS['elmslncfg']['serviceaddress'] . '.fluvac' => 'courses/services/' . $GLOBALS['elmslncfg']['host'] . '/fluvac',
'courses.' . $GLOBALS['elmslncfg']['address'] . '.fluvac' => 'courses/' . $GLOBALS['elmslncfg']['host'] . '/fluvac',

to

'data.courses.buttercupstraining.co.uk.da' => 'courses/services/bc/fluvac', 
'courses.buttercupstraining.co.uk.da' => 'courses/bc/fluvac',

I then updated the settings.php file so that $base_url= 'http://courses.buttercupstraining.co.uk/fluvac'; instead of $base_url= $GLOBALS['elmslncfg']['protocol'] . '://courses.' . $GLOBALS['elmslncfg']['address'] . '/fluvac';

The site then loaded correctly. However, I know that the way that's working isn't what we want to do since this is hardcoding in the url. Need to figure out if there is anything else I might need to update in order to get the sites with the newer configuration working.

btopro commented 5 years ago

Sorry, was on vacation when you sent the link off to this.

2019-07-11_22-58-21

Core has a patch in index.php for Drupal core/dslmcode/cores/drupal-7/index.php which points to ../../elmsln_environment/elmsln_environment.php

that file should look like this:

<?php
// hard coded would be nice if it was variable but difficult to do so
define ('ELMSLN_CFG_PATH', '/var/www/elmsln/config/scripts/drush-create-site/config.cfg');
define ('ELMSLN_ENV_HOST', '/var/www/elmsln/_elmsln_env_config/environment.php');
global $elmslncfg;

if ($cfg = file_get_contents(ELMSLN_CFG_PATH)) {
  $lines = explode("\n", $cfg);
  // read each line of the cfg file
  foreach ($lines as $line) {
  // make sure this line isn't a comment and has a = in it
    if (strpos($line, '#') !== 0 && strpos($line, '=')) {
      $tmp = explode('=', $line);
      // ensure we have 2 settings before doing this
      if (count($tmp) == 2) {
        // never pass around the dbsu
        if (!in_array($tmp[0], array('dbsu', 'dbsupw'))) {
          // strip encapsulation if it exists
          $elmslncfg[$tmp[0]] = str_replace('"', '', str_replace("'", '', $tmp[1]));
        }
      }
    }
  }
  // support the fact that $elmsln is used to reference in many bash vars
  foreach ($elmslncfg as $key => $value) {
    if (strpos($value, '$elmsln') !== FALSE) {
      $elmslncfg[$key] = str_replace('$elmsln', $elmslncfg['elmsln'], $value);
    }
  }
  // generate more values that we will want to know as shortcuts
  // sprinkle in some salt from the file system
  if (file_exists($elmslncfg['elmsln'] . '/config/SALT.txt')) {
    $elmslncfg['salt'] = file_get_contents($elmslncfg['elmsln'] . '/config/SALT.txt');
  }
}
else {
  $elmslncfg = array();
}
// allow for environment specific overrides
if (file_exists(ELMSLN_ENV_HOST)) {
  include_once(ELMSLN_ENV_HOST);
}

/var/www/elmsln/config/scripts/drush-create-site/config.cfg will look something like 2019-07-11_23-00-20

/var/www/elmsln/_elmsln_env_config/environment.php is used for deployment level overrides. It does not exist by default but if you create it, then the GLOBALS you mention can be overridden. This is an example from our staging server which mirrors and keeps prod the same but then hijacks a few of these variables to ensure the paths work out. /var/www/elmsln/_elmsln_env_config/environment.php

<?php
// this file can be used to manipulate the elmsln environment based on where it is deployed
// this could be used to migrate an entire built deploy from 1 server to another while modifying
// the addresses as needed.

// maybe you don't have certs locally
//$GLOBALS['elmslncfg']['protocol'] = 'http';
// this is probably on a different server / new address
$GLOBALS['elmslncfg']['address'] = 'elmsln.some.other.place';
$GLOBALS['elmslncfg']['serviceaddress'] = 'elmsln.some.other.place';

Hope this helps, I went to log in and the creds u gave me to the test server were dead

rickhumphries commented 5 years ago

Just had a quick look into this and I think the issue here might be that my patches hadn't applied when running git apply, which is strange because I'm pretty sure these gave me a success message when applying initially, however I can see that the files in question haven't changed. In addition, when I try to run git apply -v /var/www/elmsln/core/dslmcode/cores/drupal-7/_PATCHES/ELMSLNCFG.patch now, it throws the following errors:

Checking patch authorize.php...
error: authorize.php: No such file or directory
Checking patch cron.php...
error: cron.php: No such file or directory
Checking patch index.php...
error: index.php: No such file or directory
Checking patch install.php...
error: install.php: No such file or directory
Checking patch update.php...
error: update.php: No such file or directory
Checking patch xmlrpc.php...
error: xmlrpc.php: No such file or directory

Pretty sure @JackWillDavis had a similar issue with patches seemingly not applying too so that's something we will need to dig into.

We also don't have /var/www/elmsln/_elmsln_env_config/environment.php but that's a really useful example and just making a note that it's something we can look into setting up.

btopro commented 5 years ago

hmmm... when I apply patches I cd into the directory the patch is in (and that things ar erelative to it) and then I run patch -p1 < NAMEOFPATCH.patch.

as for environment its a bit dated but this repo had some other things things u can do there https://github.com/elmsln/_elmsln_env_config