0

My next issue is this:

attempts to push out a civilmailing result, as reported by /civicrm/admin/joblog, with this error: 'API permission check failed for Group/get call', . . . 'insufficient permission: require access CiviCRM'

From my $drush_context path, I had run sudo -u www-data ../../../vendor/civicrm/cv/bin/cv api Job.execute Same result without the sudo as www-data.

Full log entry:

Details

Parameters parsed (and passed to API method): 
a:1:{s:7:"version";i:3;}

Full message: 

> Finished execution of Mailings scheduler with result: Failure, Error
> message:  API permission check failed for Group/get call; insufficient
> permission: require access CiviCRM

My build put the following in place:

# grep -v ^# /var/spool/cron/crontabs/www-data 
*/5 * * * * /home/drupal/lib/sh/civimail_cron_job.sh process_mailing
*/15 * * * * /home/drupal/lib/sh/civimail_cron_job.sh fetch_bounces

Running that manually results in:

# sudo -u www-data /bin/bash /home/drupal/lib/sh/civimail_cron_job.sh process_mailing 
PHP Warning:  require_once(civicrm.config.php): 
failed to open stream: No such file or directory 
in /opt/local/my_client/drupal/vendor/civicrm/civicrm-core/bin/cli.class.php on line 245

PHP Fatal error:  require_once(): 
Failed opening required 'civicrm.config.php' (include_path='.:/usr/share/php') 
in /opt/local/my_client/drupal/vendor/civicrm/civicrm-core/bin/cli.class.php on line 245

closest I come to finding that file on this container is:

# locate civicrm.config.php 
/opt/local/my_client/drupal/vendor/civicrm/civicrm-drupal-8/civicrm.config.php.drupal
/opt/local/my_client/drupal/web/modules/contrib/civicrm/civicrm.config.php.drupal
# drush user:information mailprocess 
 User ID       :  23                                       
 User name     :  mailprocess                              
 User mail     :  mailprocess@uat.db.georgiagreenparty.net 
 User roles    :  authenticated                            
                  civimail_role                            
 User status   :  1                                        
# drush role:list civimail_role
 Permission        
 access CiviCRM    
 access CiviMail   
 view all contacts

UPDATING this script's listing

# cat /home/drupal/lib/sh/civimail_cron_job.sh 

#!/bin/bash

CMD=$1
CWD=/opt/local/my_client/drupal/vendor/civicrm/civicrm-core
requirements='-d require ./web/core/includes/bootstrap.inc -d require ./web/core/lib/Drupal/Core/Session/AccountInterface.php'
PHP="/usr/bin/nice -n19 /usr/bin/php ${requirements}"
PARAMS='-j -s default -u mailprocess -p asecretpassword -e Job -a '

cd $CWD; $PHP bin/cli.php $PARAMS $CMD

exit 0

UPDATE

l# CIVICRM_SETTINGS=`pwd`/web/sites/default/civicrm.settings.php /bin/bash ./civimail_cron_job.sh 
 + CMD=
 + CWD=/opt/local/my_client/drupal
 + requirements='-d require ./web/core/includes/bootstrap.inc -d require ./web/core/lib/Drupal/Core/Session/AccountInterface.php'
 + PHP='/usr/bin/nice -n19 /usr/bin/php -d require ./web/core/includes/bootstrap.inc -d require ./web/core/lib/Drupal/Core/Session/AccountInterface.php'
 + PARAMS='-j -s default -u mailprocess -p verysecret -e Job -a '
 + cd /opt/local/my_client/drupal
 + /usr/bin/nice -n19 /usr/bin/php -d require ./web/core/includes/bootstrap.inc  -d require ./web/core/lib/Drupal/Core/Session/AccountInterface.php vendor/civicrm/civicrm-core/bin/cli.php -j -s default -u mailprocess -p verysecret -e Job -a
PHP Fatal error:  Uncaught Error: Class 'Drupal\Core\Session\AccountInterface' not found in /opt/local/my_client/drupal/web/core/includes/bootstrap.inc:106
Stack trace:
#0 {main}
  thrown in /opt/local/my_client/drupal/web/core/includes/bootstrap.inc on line 106
 + exit 0

or to highlight the issue, here:
Uncaught Error: Class 'Drupal\Core\Session\AccountInterface' not found

line 106 of bootstrap.inc, reads:

const DRUPAL_ANONYMOUS_RID = AccountInterface::ANONYMOUS_ROLE;

2,738 mentions of this function in the code base, not sure what more I must do to get my code to find it.

/opt/local/my_client/drupal# grep -R 'AccountInterface' . | wc -l
2738

/opt/local/my_client/drupal# grep -R 'AccountInterface' web/ | wc -l
1365

Further UPDATE

As for testing the use of cv here, running this:

# vendor/civicrm/cv/bin/cv api job.execute 
{
    "is_error": 0,
    "version": 3,
    "count": 1,
    "values": 1
}

is yielding the following in the logs at /civicrm/admin/joblog:

Date    Job Name    Command/Job Status/Additional Information
2020-06-01 01:32:26     
Summary
Finishing scheduled jobs execution.
2020-06-01 01:32:26 Mailings scheduler  
Entity: job Action: process_mailing
Summary
Finished execution of Mailings scheduler with result: Failure, Error message: API permission check failed for Group/get call; insufficient permission: require access CiviCRM
Details


Parameters parsed (and passed to API method): 
a:1:{s:7:"version";i:3;}

Full message: 
Finished execution of Mailings scheduler with result: Failure, Error message: API permission check failed for Group/get call; insufficient permission: require access CiviCRM

2020-06-01 01:32:26 Mailings scheduler  
Entity: job Action: process_mailing
Summary
Starting execution of Mailings scheduler
Details


Parameters parsed (and passed to API method): 
a:1:{s:7:"version";i:3;}

Full message: 
Starting execution of Mailings scheduler

2020-06-01 01:32:26     
Summary
Starting scheduled jobs execution

leading me to wonder how it is I get cv to run with my mailprocess user, which has these missing permissions?

UPDATE #3

Thank you, HomoTechsual, for the --user and --cwd switches.
Had missed those.
Now using this invocation:

/usr/bin/nice -n19 /usr/bin/php \
    -d require ./web/core/includes/bootstrap.inc \
    -d require ./web/core/lib/Drupal/Core/Session/AccountInterface.php \
    /opt/local/my_client/drupal/vendor/civicrm/cv/bin/cv api job.execute \
    --cwd=/opt/local/my_client/drupal \
    --user=mailprocess

and getting this error message:

PHP Fatal error:  Uncaught Error: Class 'Drupal\Core\Session\AccountInterface' not found in /opt/local/my_client/drupal/web/core/includes/bootstrap.inc:106

UPDATE #4

This invocation now returns a result code of 0.
And still I see no evidence that it ran my civimail,
in the browser UI, at /civicrm/mailing/browse/unscheduled,
nor in the logs at /civicrm/admin/joblog.

/usr/bin/nice -n19 /usr/bin/php \
    -d require /opt/local/my_client/drupal/vendor/autoload.php \
    /opt/local/ggp_crm/drupal/vendor/civicrm/cv/bin/cv api job.execute \
    --cwd=/opt/local/ggp_crm/drupal --user=mailprocess

My script now reads:

#!/bin/bash
set -x

CMD=$1
CWD='/opt/local/my_client/drupal'
CV="${CWD}/vendor/civicrm/cv/bin/cv"
CIVIMAIL_USER='mailprocess'
requirements="-d require ${CWD}/vendor/autoload.php"
PHP="/usr/bin/nice -n19 /usr/bin/php"
ARGS="--cwd=${CWD} --user=${CIVIMAIL_USER}"

cd ${CWD}; ${PHP} ${requirements} ${CV} api job.execute ${ARGS}
exit "$?"
  • Can you try having that script run from /opt/local/my_client/drupal/ as the CWD rather than /opt/local/my_client/drupal/vendor/civicrm/civicrm-core. Also. for what it's worth - you'll find CV much more useful for cron-jobs on Drupal 8/9 than cli.php which hasn't really been updated to work with D8 or D9 which are not yet officially supported. – HomoTechsual May 30 at 21:19
  • To get CV to run as a specific user add --user=USERNAME to the end (as covered in the docs). – HomoTechsual Jun 1 at 8:19
2

You should run CV commands from the root of the website (especially on Drupal 8/9 - where support isn't as well tested for "pathing" - i.e finding the correct files to bootstrap CiviCRM).

If your website lives in /var/www/civicrm that's the directory you should be in when running CV commands (ideally!). You may find that being in /var/www/civicrm/web or /var/www/civicrm/web/modules works but chances are it'll confuse the pathfinding logic!

To run commands as a specific user you should append --user=USERNAME to the end of the command string.

To run commands via cron you should use the absolute path to CV, your site and PHP.

For example:

/usr/bin/php /usr/local/bin/cv api job.execute --cwd=/var/www/civicrm --user=admin

| improve this answer | |
  • Thank you for the --user and --cwd switches. Had missed those. Now using this invocation: /usr/bin/nice -n19 /usr/bin/php -d require ./web/core/includes/bootstrap.inc -d require ./web/core/lib/Drupal/Core/Session/AccountInterface.php /opt/local/my_client/drupal/vendor/civicrm/cv/bin/cv api job.execute --cwd=/opt/local/my_client/drupal --user=mailprocess and getting this error message: PHP Fatal error: Uncaught Error: Class 'Drupal\Core\Session\AccountInterface' not found in /opt/local/my_client/drupal/web/core/includes/bootstrap.inc:106. – Hugh Esco Jun 1 at 15:07
  • I have also tested, with no joy, but the exact same error message, several variations on this: -d includepath=/opt/local/my_client/drupal/web/core/lib – Hugh Esco Jun 1 at 15:47
  • May have just discovered the secret sauce! Further testing required, but I got not error messages and echo $? returns 0. I used this on the cli: -d require ./vendor/autoload.php. – Hugh Esco Jun 1 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.