Skip to content

Commit c5b23d9

Browse files
committed
Update preinstall script to update agent config from V2 to V3
1 parent 73061a6 commit c5b23d9

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

scripts/packages/preinstall.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ INSTANCE_GROUP=""
1616
################################
1717
###### Default variables
1818
################################
19+
export NGINX_ONE_HOST="${NGINX_AGENT_SERVER_HOST:-agent.connect.nginx.com}"
1920
export AGENT_GROUP="${AGENT_GROUP:-$(id -ng)}"
2021
RED='\033[0;31m'
2122
NC='\033[0m'
@@ -118,12 +119,13 @@ update_config_file() {
118119
echo "Backing up NGINX Agent V2 configuration to /etc/nginx-agent/nginx-agent-v2-backup.conf"
119120
cp $AGENT_CONFIG_FILE /etc/nginx-agent/nginx-agent-v2-backup.conf
120121

121-
nginx_one_host="agent.connect.nginx.com"
122122
v2_config_file=$AGENT_CONFIG_FILE
123123
v3_config_file=$AGENT_CONFIG_FILE
124124

125-
if grep -q "$nginx_one_host" ${v2_config_file}; then
126-
echo "N1 connected agent"
125+
echo "NGINX Agent server host should be ${NGINX_ONE_HOST}"
126+
127+
if grep -q "$NGINX_ONE_HOST" ${v2_config_file}; then
128+
echo "NGINX One connected agent"
127129
else
128130
echo "${RED}Previous version of NGINX Agent was not connected to NGINX One. Stopping upgrade.${NC}"
129131
exit 1
@@ -158,7 +160,7 @@ allowed_directories: ${allowed_directories}
158160
159161
command:
160162
server:
161-
host: ${nginx_one_host}
163+
host: ${NGINX_ONE_HOST}
162164
port: 443
163165
auth:
164166
token: ${token}
@@ -179,7 +181,7 @@ collector:
179181
exporters:
180182
otlp_exporters:
181183
- server:
182-
host: ${nginx_one_host}
184+
host: ${NGINX_ONE_HOST}
183185
port: 443
184186
authenticator: headers_setter
185187
tls:
@@ -190,7 +192,7 @@ collector:
190192
- action: insert
191193
key: \"authorization\"
192194
value: ${token}
193-
"
195+
"
194196

195197
echo "${v3_config_contents}" > $v3_config_file
196198
fi

scripts/packages/upgrade-agent-config.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ set -e
66
# Description:
77
# NGINX Agent script for converting NGINX AGENT V2 config format to V3 config format
88

9+
export NGINX_ONE_HOST="${NGINX_AGENT_SERVER_HOST:-agent.connect.nginx.com}"
910
RED='\033[0;31m'
1011
NC='\033[0m'
11-
N1_HOST="agent.connect.nginx.com"
1212

1313
for i in "$@"; do
1414
case $i in
@@ -29,10 +29,9 @@ for i in "$@"; do
2929
esac
3030
done
3131

32-
echo "V2 config file path = ${v2_config_file}"
33-
echo "V3 config file path = ${v3_config_file}"
32+
echo "NGINX Agent server host should be ${NGINX_ONE_HOST}"
3433

35-
if grep -q "$N1_HOST" ${v2_config_file}; then
34+
if grep -q "$NGINX_ONE_HOST" ${v2_config_file}; then
3635
echo "N1 connected agent"
3736
else
3837
echo "${RED}Previous version of NGINX Agent was not connected to NGINX One. Stopping upgrade.${NC}"
@@ -68,7 +67,7 @@ allowed_directories: ${allowed_directories}
6867
6968
command:
7069
server:
71-
host: ${N1_HOST}
70+
host: ${NGINX_ONE_HOST}
7271
port: 443
7372
auth:
7473
token: ${token}
@@ -89,7 +88,7 @@ collector:
8988
exporters:
9089
otlp_exporters:
9190
- server:
92-
host: ${N1_HOST}
91+
host: ${NGINX_ONE_HOST}
9392
port: 443
9493
authenticator: headers_setter
9594
tls:

test/docker/nginx-official-image/apk/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ WORKDIR /agent
1212
COPY ./build/${PACKAGE_NAME}.apk /agent/build/${PACKAGE_NAME}.apk
1313
COPY ./ /agent
1414

15-
RUN apk del nginx-agent \
15+
RUN apk del nginx-agent
1616
RUN apk add --allow-untrusted /agent/build/${PACKAGE_NAME}.apk
1717

1818
RUN unlink /var/log/nginx/access.log

test/docker/nginx-official-image/deb/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WORKDIR /agent
1313
COPY ./build/${PACKAGE_NAME}.deb /agent/build/${PACKAGE_NAME}.deb
1414
COPY ./ /agent
1515

16-
RUN apt-get update \
16+
RUN apt-get update \
1717
&& apt purge -y nginx-agent \
1818
&& apt install --no-install-recommends --no-install-suggests -y /agent/build/${PACKAGE_NAME}.deb \
1919
&& rm /agent/build/${PACKAGE_NAME}.deb

0 commit comments

Comments
 (0)