Skip to content

Commit 75e2fd2

Browse files
committed
chore(nodejs): exit installation if Node.js version is unsupported
1 parent 4542e93 commit 75e2fd2

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

recipes/newrelic/apm/node/linux.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ preInstall:
2525
exit 1
2626
fi
2727
28-
LOWEST_SUPPORTED_MAJOR_NODE_VERSION=16
29-
NODEJS_BINARY_PATH=$(command -v node)
30-
INSTALLED_MAJOR_NODE_VERSION=$($NODEJS_BINARY_PATH -v | awk -F '[^0-9]+' '{ print $2 }')
31-
if [ "$INSTALLED_MAJOR_NODE_VERSION" -lt "$LOWEST_SUPPORTED_MAJOR_NODE_VERSION" ]; then
32-
echo "Error: Node.js version not supported. Please upgrade to the latest supported version." >&2
33-
exit 132
34-
fi
35-
3628
ASSERT_NPM_INSTALLED=$(sudo -i -u $SUDO_USER command -v npm)
3729
if [ -z "$ASSERT_NPM_INSTALLED" ] ; then
3830
exit 2
@@ -121,6 +113,7 @@ install:
121113
label: 'Finding Node processes and installing Node agent'
122114
cmds:
123115
- |
116+
LOWEST_SUPPORTED_MAJOR_NODE_VERSION=16
124117
FOUND_PROCESSES=$(sudo -i -u $SUDO_USER newrelic-introspector-node list)
125118
if [ "$FOUND_PROCESSES" == "" ] || [ "$FOUND_PROCESSES" == "[]" ]; then
126119
echo "No Node processes found running on the host" >&2
@@ -130,6 +123,12 @@ install:
130123
for PID in "${PROCESSES[@]}"
131124
do
132125
INTROSPECTION_DATA=$(sudo -i -u $SUDO_USER newrelic-introspector-node introspect --pid ${PID})
126+
INSTALLED_MAJOR_NODE_VERSION=$(echo "${INTROSPECTION_DATA}" | grep -oP '.*\K(?<=node_version":").*?(?=\")' | cut -d. -f1)
127+
if [ "$INSTALLED_MAJOR_NODE_VERSION" -lt "$LOWEST_SUPPORTED_MAJOR_NODE_VERSION" ]; then
128+
echo "Error: Node.js version not supported. Please upgrade to the latest supported version." >&2
129+
exit 132
130+
fi
131+
133132
COMMAND=$( echo "${INTROSPECTION_DATA}" | grep -oP '.*\K(?<=pm_exec_path":").*?(?=\")' )
134133
135134
if [[ "{{.NEW_RELIC_ASSUME_YES}}" != "true" ]]; then

0 commit comments

Comments
 (0)