CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • CiviMail installation and configuration (Moderator: Donald Lobo) »
  • cron job won't send / stops at includes/database.inc
Pages: [1] 2

Author Topic: cron job won't send / stops at includes/database.inc  (Read 4763 times)

GingerFeet

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 4
  • CiviCRM version: 3.4.6 / 3.4.7
  • CMS version: Drupal 6.22
  • MySQL version: 5.1
  • PHP version: 5.3.6
cron job won't send / stops at includes/database.inc
July 14, 2011, 10:32:27 pm
Wow. Smashed something, somewhere. cron job won't send. Ack!

Drupal 6.22
CiviCRM 3.4.4
Separate DBs for Drupal & CiviCRM, same usernames & passwords for both DBs

Mail sends just fine for 1 email.
Mail sends just fine with http://<website>/civicrm/mailing/queue&reset=1
Drupal user for mail has been given all CiviCRM perms and Drupal admin perms.

Running wget with credentials to: http://<website>/sites/all/modules/civicrm/bin/civimail.cronjob.php
does not work

When I run my cron job here's what appears to happens:
  • civicrm/bin/civimail.cronjob.php fires up
  • civicrm/bin/civimail.cronjob.php says: require_once ("bin/cli.php");
  • civicrm/bin/cli.php appears to authenticate with: CRM_Utils_System::authenticateScript( true,$user,$pass );
  • civicrm/bin/cli.php asks Drupal to start with: CRM_Utils_System::loadBootStrap($user, $pass);
  • Drupal attempts to start with: includes/bootstrap.inc
  • includes/bootstrap.inc gets to a big switch: switch ($phase)
  • includes/bootstrap.inc works through the first 2 cases of: switch ($phase)
  • then, in the 3rd case it asks: require_once './includes/database.inc';
  • includes/database.inc starts: function db_set_active($name = 'default')
  • none of the variables that db_set_active wants are set
  • because they are not set it runs into: if (empty($db_url)) then try to install Drupal
  • no errors on the terminal or anywhere else

Why aren't the variables that db_set_active wants: $db_url, $db_type, $active_db, $db_conns set?
Why doesn't it hook up to the database?
What's going on?

Any explanation, insight, ideas would be helpful.

Thanks so much,

GF

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: cron job won't send / stops at includes/database.inc
July 15, 2011, 12:21:27 am
Hi, I think that's something that was fixed on a more recent version.

the cron has two modes (cli & web), and I tested on $argv to know which one it was. It seems that your website sets the argv and so it things it's cli.

check out at the end, if you don't have

Code: [Select]
// you can run this program either from an apache command, or from the cli
if ( php_sapi_name() == "cli" ) {

You need to backport a more recent version. I think I published it somewhere and it shouldn't be more complicated than copying the file.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

GingerFeet

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 4
  • CiviCRM version: 3.4.6 / 3.4.7
  • CMS version: Drupal 6.22
  • MySQL version: 5.1
  • PHP version: 5.3.6
Re: cron job won't send / stops at includes/database.inc
July 15, 2011, 11:27:37 am
Xavier,

Thank you for taking the time to look at my issue.

The issue is on production sites running CiviCRM 3.3.5.
I have set up a test site templ.yyy running 3.4.4 thinking the upgrade would solve issue.
Issue is still there, so I'm trying to understand what is going on.
It's not throwing any errors that I can find.

bin/civimail.cronjob.php on 3.4.4 that I am using contains:

Code: [Select]
you can run this program either from an apache command, or from the cli
 if ( php_sapi_name() == "cli" ) { 
   require_once ("bin/cli.php");
   $cli=new civicrm_cli ();

I want my cron job to run the php cli.
I'm calling the php cli like so:

Code: [Select]
CIVI_ROOT=/var/www/yyy/hfh/sites/all/modules/civicrm
PHP="/bin/nice -n19 /usr/bin/php"

cd $CIVI_ROOT; $PHP bin/civimail.cronjob.php -uCiviMail -p12345 -stempl.yyy

Added some echos to try to figure this out. They are saying:

Quote
Script: bin/cli.php: After:
  session_start( )
Script: bin/cli.php: After:
  CRM_Utils_System::authenticateScript( true,CiviMail,12345 );
  variable civicrm_root = /var/www/yyy/hfh/sites/all/modules/civicrm
  variable _SERVER['SCRIPT_FILENAME'] = /var/www/yyy/hfh/sites/all/modules/civicrm/bin/cli.php
Script: bin/cli.php: In front of:
  require_once 'CRM/Utils/System.php';
Script: bin/cli.php: In front of:
  CRM_Utils_System::loadBootStrap(CiviMail, 12345);
Script: CRM/Util/System.php: Start of:
  function loadBootStrap
Script: CRM/Util/System.php: In front of:
  call_user_func("CRM_Utils_System_Drupal::loadBootStrap", CiviMail, 12345, );
Script: CRM/Utils/System/Drupal.php: Start of:
  function loadBootStrap
  variables: name = CiviMail pass = 12345 uid  =
  cmsPath = /var/www/yyy/hfh
Script: This script is /var/www/yyy/hfh/includes/bootstrap.inc
Script: CRM/Utils/System/Drupal.php: After:
  require_once 'includes/bootstrap.inc';
Script: includes/bootstrap.inc: Start of:
  function _drupal_bootstrap(0)
Script: includes/bootstrap.inc: At start of:
  case DRUPAL_BOOTSTRAP_CONFIGURATION:
Script: includes/bootstrap.inc: Start of:
  function _drupal_bootstrap(1)
Script: includes/bootstrap.inc: At start of:
  case DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE:
Script: includes/bootstrap.inc: Start of:
  function _drupal_bootstrap(2)
Script: includes/bootstrap.inc: At start of:
  case DRUPAL_BOOTSTRAP_DATABASE:
Script: includes/database.inc
Script: includes/bootstrap.inc: In front of:
  require_once './includes/database.inc';
Script: includes/database.inc: At start of:
  function db_set_active(default = 'default')
  variables:
  db_url =
  db_type =
  active_db =
  db_conns =
Script: includes/database.inc: Inside of:
  if (empty($db_url))
  if (empty())

I interpret the echos to mean:

  • the cron job fires up bin/civimail.cronjob.php
  • appears to authenticate
  • bin/cli.php function authenticate never reaches the end
  • CRM/Util/System.php function loadBootStrap never reaches the end
  • CRM/Utils/System/Drupal.php function loadBootStrap never passes @drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  • includes/bootstrap.inc never reaches end of case DRUPAL_BOOTSTRAP_DATABASE:
  • includes/database.inc says that if $db_url is empty, then try to install Drupal
  • The cron job is trying to install Drupal?

Why aren't the $db_url, $db_type, $active_db, $db_conns set inside of function db_set_active?

This is not easy for me...
What tools should I be using to help figure this out?
Have I done something really silly somewhere else that's messing things up?

Thanks,
GF

GingerFeet

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 4
  • CiviCRM version: 3.4.6 / 3.4.7
  • CMS version: Drupal 6.22
  • MySQL version: 5.1
  • PHP version: 5.3.6
Re: cron job won't send / stops at includes/database.inc
July 15, 2011, 12:24:06 pm
Hi All,

The reason why $db_url is not set, is because bin/cli.php never asks for it.

I added
Quote
require_once '/var/www/yyy/hfh/sites/templ.yyy/settings.php';

at the top of bin/cli.php. How do I do that so that the path is a variable? Not hard coded?

Adding the require_once appears to be an improvement, now it throws an error:
Quote
PHP Fatal error:  session_start(): Failed to initialize storage module: user (path: /var/lib/php/session) in /var/www/yyy/hfh/sites/all/modules/civicrm/bin/cli.php.echo on line 93

Any ideas?

Thanks,
GF

GingerFeet

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 4
  • CiviCRM version: 3.4.6 / 3.4.7
  • CMS version: Drupal 6.22
  • MySQL version: 5.1
  • PHP version: 5.3.6
Re: cron job won't send / stops at includes/database.inc
July 15, 2011, 12:35:33 pm
Hi All,

Googling around it appears that it doesn't make sense to use session_start() in a cli program.

So I commented out session_start() in bin/cli.php.

Now when I run my cron job my last echo is:

Quote
Script: bin/civimail.cronjob.php: At start of:
  function processQueue

Whoo-hoo!

Well, maybe I better hold back on that until I actually run a real test.

Thanks,
GF
 

GingerFeet

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 4
  • CiviCRM version: 3.4.6 / 3.4.7
  • CMS version: Drupal 6.22
  • MySQL version: 5.1
  • PHP version: 5.3.6
Re: cron job won't send / stops at includes/database.inc
July 15, 2011, 01:29:20 pm
Hello All,

Yes, it works. cron job now sends the queued mail using php cli.

And my /etc/php.ini file has been set to:
session.save_handler = files

So these instructions:
http://www.caneblu.com/2009/01/fatal-error-session_start-failed-to-initialize-storage-module/
won't get rid of the fatal PHP error. It appears that the session_start() does need to be commented out.

How do I write:
require_once '/var/www/yyy/hfh/sites/templ.yyy/settings.php';
in bin/cli.php so that the path is a variable?

Thanks,
GF


GingerFeet

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 4
  • CiviCRM version: 3.4.6 / 3.4.7
  • CMS version: Drupal 6.22
  • MySQL version: 5.1
  • PHP version: 5.3.6
Re: cron job won't send / stops at includes/database.inc
July 15, 2011, 03:00:42 pm
Hello All,

I don't think the require_once '/var/www/yyy/hfh/sites/templ.yyy/settings.php'; should go in bin/cli.php
It should go in CRM/Utils/System/Drupal.php

I'm suggesting 2 edits:

1) Add the following to CRM/Utils/System/Drupal.php
Code: [Select]
if ( php_sapi_name() == "cli" ) {
  //bin/php.cli in function SetEnv sets the HTTP_HOST to the site
  //supplied on the command line.
  $settings_php = $cmsPath."/sites/".$_SERVER['HTTP_HOST']."/settings.php";
             
  if ( !file_exists( "$settings_php" ) ) {
    echo '<br />Sorry, could not locate settings.php.';                                   
    exit( );
  } 
             
  require_once "$settings_php";
} 

The above code should be inserted directly after:
Code: [Select]
     static function loadBootStrap($name = null, $pass = null, $uid = null )
     {       
         //take the cms root path.
         $cmsPath = self::cmsRootPath( );


2) Comment out session_start() in bin/cli.php

How do we get this tested, approved, and into the code?

GF

« Last Edit: July 15, 2011, 03:09:33 pm by GingerFeet »

GingerFeet

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 4
  • CiviCRM version: 3.4.6 / 3.4.7
  • CMS version: Drupal 6.22
  • MySQL version: 5.1
  • PHP version: 5.3.6
Re: cron job won't send / stops at includes/database.inc
July 15, 2011, 03:22:17 pm
Aggghh!

It's not working.

GF

GingerFeet

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 4
  • CiviCRM version: 3.4.6 / 3.4.7
  • CMS version: Drupal 6.22
  • MySQL version: 5.1
  • PHP version: 5.3.6
Re: cron job won't send / stops at includes/database.inc
July 15, 2011, 04:17:22 pm
Hah! Skinned it!

1) This code:
   
Code: [Select]
         if ( php_sapi_name() == "cli" ) {
           $CRM_Utils_System_Drupal = new CRM_Utils_System_Drupal();
           $cmsPath = $CRM_Utils_System_Drupal->cmsRootPath();
           //bin/php.cli in function SetEnv sets the HTTP_HOST
           //to the site supplied on the command line.
           $settings_php = $cmsPath."/sites/".$_SERVER['HTTP_HOST']."/settings.php";
           if ( !file_exists( "$settings_php" ) ) {
             echo '<br />Sorry, could not locate settings.php.';
             exit( );
           }
           global $db_url;
           require_once "$settings_php";
         }

Needs to be added to CRM/Utils/System.php

Right after:

Code: [Select]
static function loadBootStrap($name = null, $pass = null, $uid = null)
     {
         $config = CRM_Core_Config::singleton();
         require_once(str_replace('_', DIRECTORY_SEPARATOR, $config->userFrameworkClass) . '.php');

And

2) Comment out session_start() in bin/cli.php

How does it get tested, approved, added to the codebase?

Thanks,
GF
     

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: cron job won't send / stops at includes/database.inc
July 15, 2011, 09:08:08 pm
Hi,

Have you tested with Joomla? Seems to introduce a drupal only code in the common base ( CRM_Utils_System_Drupal->cmsRootPath ).

They are 4 modes to test
- via web
- cli with location_settings (civicrm not under sites/all/modules but only symlinked)
- cli  "normal" on a sites/domain
- cli on a sites/default

Which one(s) have you tested?

Otherwise, the process for bug is to create an issue and attach it as a patch (svn diff). For this one you can assign it to me.

X+


X+


-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: cron job won't send / stops at includes/database.inc
July 16, 2011, 12:41:08 am

since we are now bootstrapping drupal, not sure why we need session_start in cli.php? maybe we should add that to the joomla bootstrap?

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: cron job won't send / stops at includes/database.inc
July 16, 2011, 01:48:29 am
When did we start bootstrapping drupal? I have a problem around this on 3.2.5 - was it after that?
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: cron job won't send / stops at includes/database.inc
July 16, 2011, 03:52:06 am
Could be (was after a code sprint @oxford I think).

On my config, I had to disable the bootstrap on some installs for the cli. at the core didn't have problems on their machine, I assumed I had bad karma and commented out the bootstrap.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

GingerFeet

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 4
  • CiviCRM version: 3.4.6 / 3.4.7
  • CMS version: Drupal 6.22
  • MySQL version: 5.1
  • PHP version: 5.3.6
Re: cron job won't send / stops at includes/database.inc
July 16, 2011, 10:21:55 am
Quote from: xavier on July 15, 2011, 09:08:08 pm
Hi,

Have you tested with Joomla? Seems to introduce a drupal only code in the common base ( CRM_Utils_System_Drupal->cmsRootPath ).

They are 4 modes to test
- via web
- cli with location_settings (civicrm not under sites/all/modules but only symlinked)
- cli  "normal" on a sites/domain
- cli on a sites/default

Which one(s) have you tested?

Otherwise, the process for bug is to create an issue and attach it as a patch (svn diff). For this one you can assign it to me.

X+


X+

Hi Xavier,

I have only tested:
Drupal / cli  "normal" on a sites/domain

GF

GingerFeet

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 4
  • CiviCRM version: 3.4.6 / 3.4.7
  • CMS version: Drupal 6.22
  • MySQL version: 5.1
  • PHP version: 5.3.6
Re: cron job won't send / stops at includes/database.inc
August 03, 2011, 06:58:43 pm
Hey,

Things were not going so great, so I installed 3.4.5 to give it a whirl.

The first error:
Quote
Usage: Please define CIVICRM_CONFDIR in settings_location.php at the top level civicrm directory
So I wrote a settings_location.php, and drove past that error.

The second error:
Quote
PHP Warning:  session_start(): open(/var/lib/php/session/sess_cnvselugc03fof816vjqbth480, O_RDWR) failed: Permission denied (13) in /var/www/dev/test/sites/all/modules/civicrm/bin/cli.php on line 85
So I commented out the session in civicrm/bin/cli.php

Still no satisfaction. Mail never sending. So I hacked civicrm/CRM/Utils/System.php to get my variables, and all is right with the world.

Is my installation messed up? Why do I have to do this?

GF

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • CiviMail installation and configuration (Moderator: Donald Lobo) »
  • cron job won't send / stops at includes/database.inc

This forum was archived on 2017-11-26.