Skip to content

Commit

Permalink
PHP recipe application name
Browse files Browse the repository at this point in the history
  • Loading branch information
rthorn-nr authored Mar 31, 2023
1 parent 196832e commit 6c71afd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
18 changes: 11 additions & 7 deletions recipes/newrelic/apm/php/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,22 @@ install:
read -r APPLICATION_RESTART
APPLICATION_RESTART=${APPLICATION_RESTART:-y}
echo "$APPLICATION_NAME $APPLICATION_RESTART" > "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
echo "$APPLICATION_NAME" > "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
echo "$APPLICATION_RESTART" >> "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
fi
# Interactive install with NEW_RELIC_APPLICATION_NAME envar set, uses envar and also defaults to service restart
if [[ "{{.NEW_RELIC_ASSUME_YES}}" != "true" && ! -z $NEW_RELIC_APPLICATION_NAME ]]; then
echo "$NEW_RELIC_APPLICATION_NAME y" > "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
echo "$NEW_RELIC_APPLICATION_NAME" > "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
echo "y" >> "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
fi
verify_continue:
cmds:
- |
if [[ "{{.NEW_RELIC_ASSUME_YES}}" != "true" ]]; then
read -r APPLICATION_NAME APPLICATION_RESTART < "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
read -r APPLICATION_NAME < "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
read -r APPLICATION_RESTART < <(tail -n 1 "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}")
else
APPLICATION_NAME="{{.NEW_RELIC_APPLICATION_NAME}}"
APPLICATION_RESTART="{{.NEW_RELIC_APPLICATION_RESTART}}"
Expand All @@ -230,7 +233,8 @@ install:
if [ -f "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}" ]; then
rm -f "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}" 2>/dev/null
fi
echo "$APPLICATION_NAME $APPLICATION_RESTART" > "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
echo "$APPLICATION_NAME" > "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
echo "$APPLICATION_RESTART" >> "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
fi
echo -e "{{.WHITE}}Confirmation: The following options were selected. If you wish to change an option, please select 'n' at the prompt and restart the installation."
Expand Down Expand Up @@ -486,7 +490,7 @@ install:
# files.
#
APPLICATION_NAME=$(cat "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}" | cut -d' ' -f1 | xargs echo -n)
read -r APPLICATION_NAME < "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
INI_DIRS=($WEB_INI_DIR $CLI_INI_DIR)
for dirs in $INI_DIRS; do
for ini in $dirs; do
Expand Down Expand Up @@ -529,7 +533,7 @@ install:
APPLICATION_NAME=${APPLICATION_NAME//\&/\&} # Replace every occurrence of '&' with "\&"
fi
sed -i "s/newrelic.appname = \"PHP Application\"/newrelic.appname = \"${APPLICATION_NAME}\"/" $ini_full_name
sed -i "s/newrelic.appname = \"[^\"]*\"/newrelic.appname = \"${APPLICATION_NAME}\"/" $ini_full_name
if [ "{{.NEW_RELIC_REGION}}" = "STAGING" ]; then
sed -i 's/;newrelic.daemon.collector_host = ""/newrelic.daemon.collector_host = "staging-collector.newrelic.com"/' $ini_full_name
sed -i 's/;newrelic.loglevel = "info"/newrelic.loglevel = "verbosedebug"/' $ini_full_name
Expand Down Expand Up @@ -595,7 +599,7 @@ install:
# Case: apache only or nginx only, they respective service needs to be restarted.
# This means only restart the first process in processes_to_restart.txt.
#
APPLICATION_RESTART=$(cat "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}" | cut -d' ' -f2 | xargs echo -n)
read -r APPLICATION_RESTART < <(tail -n 1 "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}")
if [ "$APPLICATION_RESTART" = "y" ] && [ -f "{{.TMP_INSTALL_DIR}}/processes_to_restart.txt" ]; then
cd {{.TMP_INSTALL_DIR}}
read -r process user_name < "{{.TMP_INSTALL_DIR}}/processes_to_restart.txt"
Expand Down
19 changes: 12 additions & 7 deletions recipes/newrelic/apm/php/redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,22 @@ install:
read -r APPLICATION_RESTART
APPLICATION_RESTART=${APPLICATION_RESTART:-y}
echo "$APPLICATION_NAME $APPLICATION_RESTART" > "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
echo "$APPLICATION_NAME" > "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
echo "$APPLICATION_RESTART" >> "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
fi
# Interactive install with NEW_RELIC_APPLICATION_NAME envar set, uses envar and also defaults to service restart
if [[ "{{.NEW_RELIC_ASSUME_YES}}" != "true" && ! -z $NEW_RELIC_APPLICATION_NAME ]]; then
echo "$NEW_RELIC_APPLICATION_NAME y" > "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
echo "$NEW_RELIC_APPLICATION_NAME" > "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
echo "y" >> "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
fi
verify_continue:
cmds:
- |
if [[ "{{.NEW_RELIC_ASSUME_YES}}" != "true" ]]; then
read -r APPLICATION_NAME APPLICATION_RESTART < "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
read -r APPLICATION_NAME < "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
read -r APPLICATION_RESTART < <(tail -n 1 "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}")
else
APPLICATION_NAME="{{.NEW_RELIC_APPLICATION_NAME}}"
APPLICATION_RESTART="{{.NEW_RELIC_APPLICATION_RESTART}}"
Expand All @@ -212,7 +215,8 @@ install:
if [ -f "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}" ]; then
rm -f "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}" 2>/dev/null
fi
echo "$APPLICATION_NAME $APPLICATION_RESTART" > "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
echo "$APPLICATION_NAME" > "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
echo "$APPLICATION_RESTART" >> "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
fi
echo -e "{{.WHITE}}Confirmation: The following options were selected. If you wish to change an option, please select 'n' at the prompt and restart the installation."
Expand Down Expand Up @@ -444,7 +448,7 @@ install:
# Loop through all the directories where the installation placed `newrelic.ini`
# files.
#
APPLICATION_NAME=$(cat "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}" | cut -d' ' -f1 | xargs echo -n)
read -r APPLICATION_NAME < "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}"
for ini in $WEB_INI_DIR $CLI_INI_DIR; do
ini_full_name="${ini}/newrelic.ini"
if [ ! -f "$ini_full_name" ]; then
Expand All @@ -461,7 +465,8 @@ install:
APPLICATION_NAME=${APPLICATION_NAME//\&/\&} # Replace every occurrence of '&' with "\&"
fi
sed -i "s/newrelic.appname = \"PHP Application\"/newrelic.appname = \"${APPLICATION_NAME}\"/" $ini_full_name
sed -i "s/newrelic\.appname = \"[^\"]*\"/newrelic.appname = \"${APPLICATION_NAME}\"/" $ini_full_name
if [ "{{.NEW_RELIC_REGION}}" = "STAGING" ]; then
sed -i 's/;newrelic.daemon.collector_host = ""/newrelic.daemon.collector_host = "staging-collector.newrelic.com"/' $ini_full_name
fi
Expand All @@ -486,7 +491,7 @@ install:
# Case: apache only or nginx only, they respective service needs to be restarted.
# This means only restart the first process in processes_to_restart.txt.
#
APPLICATION_RESTART=$(cat "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}" | cut -d' ' -f2 | xargs echo -n)
read -r APPLICATION_RESTART < <(tail -n 1 "{{.TMP_INSTALL_DIR}}/{{.USER_INPUT}}")
if [ "$APPLICATION_RESTART" = "y" ] && [ -f "{{.TMP_INSTALL_DIR}}/processes_to_restart.txt" ]; then
cd {{.TMP_INSTALL_DIR}}
read -r process user_name < "{{.TMP_INSTALL_DIR}}/processes_to_restart.txt"
Expand Down

0 comments on commit 6c71afd

Please sign in to comment.