From e3a21d0e9c31a70beb1b4ac9ed2134b0d21b1000 Mon Sep 17 00:00:00 2001 From: Thomas Fleming Date: Mon, 9 Dec 2024 15:17:52 -0500 Subject: [PATCH 1/3] Added Acquia scrupt to settings.php --- docroot/sites/default/settings.php | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) 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 + } +} From 8934c18e6cc32621f1c23f051967ebe81d5cb5ec Mon Sep 17 00:00:00 2001 From: Thomas Fleming Date: Mon, 9 Dec 2024 15:20:57 -0500 Subject: [PATCH 2/3] Added transaction shell script --- scripts/drush-transaction.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 scripts/drush-transaction.sh diff --git a/scripts/drush-transaction.sh b/scripts/drush-transaction.sh new file mode 100755 index 0000000000..14c9430462 --- /dev/null +++ b/scripts/drush-transaction.sh @@ -0,0 +1,36 @@ +#!/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 -e "***** Script Completed: $(date --rfc-3339=seconds) *****\\n" From db28f19f74a2fa24c9cdfeabbed8e87fa07567d0 Mon Sep 17 00:00:00 2001 From: Thomas Fleming Date: Mon, 9 Dec 2024 15:58:03 -0500 Subject: [PATCH 3/3] added entity tracking --- scripts/drush-transaction.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/drush-transaction.sh b/scripts/drush-transaction.sh index 14c9430462..12be4b0e59 100755 --- a/scripts/drush-transaction.sh +++ b/scripts/drush-transaction.sh @@ -33,4 +33,9 @@ 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"