Skip to content

Commit d499f9a

Browse files
chore(php): refactored the code
1 parent 5461f23 commit d499f9a

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

recipes/newrelic/apm/php/debian.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ install:
375375
cmds:
376376
- |
377377
echo -e "{{.ARROW}}Installing New Relic PHP Agent package{{.GRAY}}"
378+
sudo DEBIAN_FRONTEND=noninteractive apt-get install newrelic-php5 -y -qq
378379
silent: true
379380

380381
install_tarball:
@@ -405,11 +406,12 @@ install:
405406
AGENT_TARBALL="$AGENT.tar.gz"
406407
# Lack of '/' is important. See above comment where $RELEASE_URL is
407408
# defined. An extraneous '/' here treats the URL as an HTML doc.
408-
curl -s -O "$RELEASE_URL$AGENT_TARBALL"
409+
curl -s "$RELEASE_URL$AGENT_TARBALL" -o "$AGENT_TARBALL"
409410
gzip -dc "$AGENT_TARBALL" | tar xf -
410-
cd "$AGENT"
411+
pushd "$AGENT" > /dev/null
411412
echo -e "{{.WHITE}}Running PHP Agent installer{{.GRAY}}"
412413
NR_INSTALL_USE_CP_NOT_LN=1 NR_INSTALL_SILENT=true NR_INSTALL_KEY="{{.NEW_RELIC_LICENSE_KEY}}" ./newrelic-install install
414+
popd > /dev/null
413415
414416
configure:
415417
cmds:
@@ -459,26 +461,25 @@ install:
459461
echo -e "{{.YELLOW}}cli dir path after change is $CLI_INI_DIR{{.GRAY}}"
460462
echo -e "{{.YELLOW}}web dir path after change is $WEB_INI_DIR{{.GRAY}}"
461463
INI_DIRS=($WEB_INI_DIR $CLI_INI_DIR)
462-
for dirs in "${INI_DIRS[@]}"; do
464+
for dirs in $INI_DIRS; do
463465
for ini in $dirs; do
464466
echo -e "{{.YELLOW}}ini path is $ini{{.GRAY}}"
465467
#
466468
# Get the PHP INI Directory associated with this specific NR INI file
467469
#
468470
php_ini_dir=$(echo $ini | sed -n 's/\(.*\)\/conf.d/\1/p')
469-
if [ -z "${php_ini_dir}" ]; then
470-
if [[ "$dirs" == "$WEB_INI_DIR" ]]; then
471+
if [[ -z "${php_ini_dir}" ]]; then
472+
if [[ -z "${CLI_DIRS}" ]]; then
471473
if [[ -d "${ini}/../apache2" ]]; then
472474
php_ini_dir="${ini}/../apache2"
473475
fi
474476
if [[ -d "${ini}/../fpm" ]]; then
475477
php_ini_dir="${ini}/../fpm"
476478
fi
477-
elif [[ "$dirs" == "$CLI_INI_DIR" ]]; then
478-
php_ini_dir="${php_ini_dir}/../cli"
479+
elif [[ -d "${ini}/../cli" ]]; then
480+
php_ini_dir="${ini}/../cli"
479481
else
480-
echo -e "something went wrong while checking for paths"
481-
php_ini_dir=${ini}
482+
php_ini_dir=$ini
482483
fi
483484
fi
484485
echo -e "{{.YELLOW}}php ini dir path is: $php_ini_dir{{.GRAY}}"
@@ -533,7 +534,7 @@ install:
533534
#
534535
target_ini_dir="/etc/php5/conf.d/"
535536
if [ -x /usr/sbin/phpquery ]; then
536-
target_ini_dir="${ini}"
537+
target_ini_dir="${php_ini_dir}/../mods-available/"
537538
elif [ -x /usr/sbin/php5endmod ]; then
538539
target_ini_dir="/etc/php5/mods-available/"
539540
fi
@@ -546,8 +547,9 @@ install:
546547
# This ensures we always get the most up to date newrelic.ini file on the
547548
# system.
548549
#
549-
550-
if [ ! -f "${target_ini_dir}/$(basename ${ini_full_name})" ]; then
550+
551+
ini_dir=$(dirname "$ini_full_name")
552+
if [[ "$ini_dir" != "$target_ini_dir" ]]; then
551553
mv "${ini_full_name}" "${target_ini_dir}"
552554
fi
553555
@@ -660,10 +662,9 @@ install:
660662
#
661663
info_text="{{.TMP_INSTALL_DIR}}/cli_info.txt"
662664
fi
663-
cat "${info_text}"
664665
while read -r bin_loc php_ini_dir nr_ini_dir; do
665666
echo -e "bin_loc is ${bin_loc}, php_ini_dir is ${php_ini_dir} and nr_ini_dir is ${nr_ini_dir}"
666-
sudo -u $nonpriv_user $bin_loc -c "${php_ini_dir}/php.ini" -c "${nr_ini_dir}/newrelic.ini" -n --ini &>/dev/null
667+
sudo -u $nonpriv_user $bin_loc -c "${php_ini_dir}/php.ini" -c "${nr_ini_dir}/newrelic.ini" -n --ini
667668
done < "${info_text}"
668669
done
669670
else

0 commit comments

Comments
 (0)