diff --git a/docroot/sites/default/settings.php b/docroot/sites/default/settings.php index 9d22751ac2..bdba36a8cd 100644 --- a/docroot/sites/default/settings.php +++ b/docroot/sites/default/settings.php @@ -221,3 +221,42 @@ if (extension_loaded('newrelic')) { // Ensure PHP agent is available newrelic_disable_autorum(); } + +// If this is a CLI call, set some parameters so that +// it can be logged to New Relic +if (PHP_SAPI === 'cli') { + $cli_arg = NULL; + + $_SERVER['REQUEST_METHOD'] = 'CLI'; + + // If we are in a drush environment, set the REQUEST_URI to the command. + try { + // Check if we have the \Drush\Drush::input() method - that is we expect to use a later Drush version + + $method = new ReflectionMethod('\Drush\Drush::input'); + + if ( $method->isStatic() ) + { + // Method exists! + // Retrieve the drush command and set New Relic transaction name + $cli_arg = \Drush\Drush::input()->getFirstArgument(); + $_SERVER['REQUEST_URI'] = $cli_arg; + + if (extension_loaded('newrelic')) { + // Using the function newrelic_name_transaction() + // + if (function_exists('newrelic_name_transaction') && !empty($cli_arg)) { + $cli_arg = 'drush ' . $cli_arg; + + // Define the Transaction Name for New Relic + newrelic_name_transaction($cli_arg); + } + } + } + } + catch ( ReflectionException $e ) + { + // The method \Drush\Drush::input() method does not exist + // We will do nothing, so as to allow rest of script to continue + } +} diff --git a/scripts/drush-transaction.sh b/scripts/drush-transaction.sh new file mode 100755 index 0000000000..12be4b0e59 --- /dev/null +++ b/scripts/drush-transaction.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +if [[ $# -ne 2 ]]; then + echo "Script requires two parameters" >&2 + echo "${0} AH_SITE_NAME SITE_DOMAIN" >&2 + exit 2 +fi + +# if there is a $HOME/.ssh/environment file, +# then read each line and export each variable from the file +SSH_ENVIRONMENT=$HOME/.ssh/environment +if [[ -f "${SSH_ENVIRONMENT}" ]]; then + #export each of the variables from the file + while read line; do export $line; done < ${SSH_ENVIRONMENT} +fi + +logfile="/shared/logs/drush-cron.log" +exec > >(/usr/bin/tee -a "$logfile") 2>&1 +if [ -n "${2}" ]; then + uri="${2}" +else + uri="${AH_SITE_NAME}.${AH_REALM}.acquia-sites.com" +fi + +#echo "URI: ${uri}" +echo "***** Script ${0} Started: $(date --rfc-3339=seconds) *****" + +echo "***** Running Drush status" +PHP_INI_SCAN_DIR=:$HOME/.drush drush --root="/var/www/html/${AH_SITE_NAME}/docroot/" --uri="${uri}" status +echo + +echo "***** Running Drush cron" +PHP_INI_SCAN_DIR=:$HOME/.drush drush --root="/var/www/html/${AH_SITE_NAME}/docroot/" --uri="${uri}" cron +echo + +echo "***** Running Drush entity usage tracking" +PHP_INI_SCAN_DIR=:$HOME/.drush drush --root="/var/www/html/${AH_SITE_NAME}/docroot/" --uri="${uri}" --time-limit=60 queue:run entity_usage_tracker + +echo + +echo -e "***** Script Completed: $(date --rfc-3339=seconds) *****\\n"