Skip to content

Commit 9a88205

Browse files
authored
Remove unsupported from agent v3 install (#987)
1 parent dd572a2 commit 9a88205

File tree

3 files changed

+6
-235
lines changed

3 files changed

+6
-235
lines changed

scripts/packages/postinstall.sh

Lines changed: 5 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
# shellcheck source=/dev/null
55
. /etc/os-release
66

7-
if [ "$ID" = "freebsd" ]; then
8-
BSD_HIER="/usr/local"
9-
AGENT_EXE="${BSD_HIER}/bin/nginx-agent"
10-
else
11-
AGENT_EXE="/usr/bin/nginx-agent"
12-
BSD_HIER=""
13-
fi
7+
8+
AGENT_EXE="/usr/bin/nginx-agent"
149
AGENT_RUN_DIR="/var/run/nginx-agent"
1510
AGENT_LOG_DIR="/var/log/nginx-agent"
1611
AGENT_UNIT_LOCATION="/etc/systemd/system"
@@ -107,18 +102,6 @@ create_agent_group() {
107102
fi
108103
fi
109104

110-
if [ "$ID" = "freebsd" ]; then
111-
printf "PostInstall: Adding nginx-agent group %s\n" "${AGENT_GROUP}"
112-
pw groupadd "${AGENT_GROUP}"
113-
114-
printf "PostInstall: Adding NGINX / agent user %s to group %s\n" "${AGENT_USER}" "${AGENT_GROUP}"
115-
pw groupmod "${AGENT_GROUP}" -M "${AGENT_USER}"
116-
if [ "${WORKER_USER}" ]; then
117-
printf "PostInstall: Adding NGINX Worker user %s to group %s\n" "${WORKER_USER}" "${AGENT_GROUP}"
118-
pw groupmod "${AGENT_GROUP}" -M "${WORKER_USER}"
119-
fi
120-
fi
121-
122105
if [ "$ID" = "alpine" ]; then
123106
printf "PostInstall: Adding nginx-agent group %s\n" "${AGENT_GROUP}"
124107
addgroup "${AGENT_GROUP}"
@@ -168,118 +151,9 @@ update_unit_file() {
168151
printf "PostInstall: Set the enabled flag for the service unit\n"
169152
systemctl enable "${AGENT_UNIT_FILE}"
170153
fi
171-
172-
if [ "$ID" = "freebsd" ]; then
173-
printf "PostInstall: Enabling NGINX Agent Service\n"
174-
sysrc nginx_agent_enable=YES
175-
fi
176-
}
177-
178-
add_default_config_file() {
179-
if [ ! -f "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf ]; then
180-
printf "PostInstall: Creating default nginx-agent.conf file\n"
181-
cat <<EOF > "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf
182-
#
183-
# /etc/nginx-agent/nginx-agent.conf
184-
#
185-
# Configuration file for NGINX Agent.
186-
#
187-
# This file is to track NGINX Agent configuration values that are meant to be statically set. There
188-
# are additional NGINX Agent configuration values that are set via the API and NGINX Agent install script
189-
# which can be found in /var/lib/nginx-agent/agent-dynamic.conf.
190-
191-
# specify the server grpc port to connect to
192-
server:
193-
# host of the control plane
194-
host: 127.0.0.1
195-
grpcPort: 54789
196-
# provide servername overrides if using SNI
197-
# metrics: ""
198-
# command: ""
199-
# tls options
200-
tls:
201-
# enable tls in the nginx-agent setup for grpcs
202-
# default to enable to connect with tls connection but without client cert for mtls
203-
enable: false
204-
# specify the absolute path to the CA certificate file to use for verifying
205-
# the server certificate (also requires 'skip_verify: false' below)
206-
# by default, this will be the trusted root CAs found in the OS CA store
207-
# ca: /etc/nginx-agent/ca.pem
208-
# specify the absolute path to the client cert, when mtls is enabled
209-
# cert: /etc/nginx-agent/client.crt
210-
# specify the absolute path to the client cert key, when mtls is enabled
211-
# key: /etc/nginx-agent/client.key
212-
# controls whether the server certificate chain and host name are verified.
213-
# for production use, see instructions for configuring TLS
214-
skip_verify: true
215-
log:
216-
# set log level (panic, fatal, error, info, debug, trace; default "info")
217-
level: info
218-
# set log path. if empty, don't log to file.
219-
path: /var/log/nginx-agent/
220-
# data plane status message / 'heartbeat'
221-
nginx:
222-
# path of NGINX logs to exclude
223-
exclude_logs: ""
224-
socket: "unix:/var/run/nginx-agent/nginx.sock"
225-
226-
dataplane:
227-
status:
228-
# poll interval for data plane status - the frequency the NGINX Agent will query the dataplane for changes
229-
poll_interval: 30s
230-
# report interval for data plane status - the maximum duration to wait before syncing dataplane information if no updates have being observed
231-
report_interval: 24h
232-
metrics:
233-
# specify the size of a buffer to build before sending metrics
234-
bulk_size: 20
235-
# specify metrics poll interval
236-
report_interval: 1m
237-
collection_interval: 15s
238-
mode: aggregated
239-
240-
# OSS NGINX default config path
241-
# path to aux file dirs can also be added
242-
allowed_directories:
243-
- /etc/nginx
244-
- /usr/local/etc/nginx
245-
- /usr/share/nginx/modules
246-
- /etc/nms
247-
api:
248-
# default port for NGINX Agent API, this is for the server configuration of the REST API
249-
port: 8081
250-
EOF
251-
printf "PostInstall: Updating file permissions for nginx-agent.conf to 0640\n"
252-
chmod 0640 "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf
253-
fi
254-
}
255-
256-
upgrade_config_file() {
257-
if [ -f "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf ]; then
258-
extensions=""
259-
if grep -q "advanced_metrics:" "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf; then
260-
extensions="${extensions} advanced-metrics"
261-
fi
262-
if grep -q "nginx_app_protect:" "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf; then
263-
extensions="${extensions} nginx-app-protect"
264-
fi
265-
if grep -q "nap_monitoring:" "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf; then
266-
extensions="${extensions} nap-monitoring"
267-
fi
268-
if ! grep -q "extensions:" "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf && [ "${#extensions}" -ne "0" ]; then
269-
printf "PostInstall: Updating nginx-agent.conf to include extensions array\n"
270-
printf "\nextensions:\n" >> "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf
271-
for extension in ${extensions}; do
272-
echo " - $extension" >> "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf
273-
done
274-
fi
275-
fi
276154
}
277155

278156
restart_agent_if_required() {
279-
if [ "${ID}" = "freebsd" ]; then
280-
# https://github.com/freebsd/pkg/pull/2128
281-
return
282-
fi
283157
if service nginx-agent status >/dev/null 2>&1; then
284158
printf "PostInstall: Restarting nginx agent\n"
285159
service nginx-agent restart || true
@@ -291,15 +165,10 @@ summary() {
291165
echo " NGINX Agent package has been successfully installed."
292166
echo ""
293167
echo " Please follow the next steps to start the software:"
294-
if [ "$ID" = "freebsd" ]; then
295-
echo " sudo service nginx-agent start"
296-
echo ""
297-
else
298-
echo " sudo systemctl start nginx-agent"
299-
echo ""
300-
fi
168+
echo " sudo systemctl start nginx-agent"
169+
echo ""
301170
echo " Configuration settings can be adjusted here:"
302-
echo " ${BSD_HIER}/etc/nginx-agent/nginx-agent.conf"
171+
echo " /etc/nginx-agent/nginx-agent.conf"
303172
echo ""
304173
echo "----------------------------------------------------------------------"
305174
}
@@ -314,8 +183,6 @@ summary() {
314183
create_agent_group
315184
create_run_dir
316185
update_unit_file
317-
add_default_config_file
318-
upgrade_config_file
319186
restart_agent_if_required
320187
summary
321188
}

scripts/packages/postremove.sh

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44
# shellcheck source=/dev/null
55
. /etc/os-release
66

7-
stop_agent_freebsd() {
8-
echo "Stopping nginx-agent service"
9-
service nginx-agent onestop >/dev/null 2>&1 || true
10-
}
11-
12-
disable_agent_freebsd() {
13-
echo "Disabling nginx-agent service"
14-
sysrc -x nginx_agent_enable >/dev/null 2>&1 || true
15-
}
16-
177
stop_agent_systemd() {
188
echo "Stopping nginx-agent service"
199
systemctl stop nginx-agent >/dev/null 2>&1 || true
@@ -35,11 +25,6 @@ cleanup() {
3525
}
3626

3727
case "$ID" in
38-
freebsd)
39-
stop_agent_freebsd
40-
disable_agent_freebsd
41-
cleanup
42-
;;
4328
debian|ubuntu)
4429
if [ "$1" = "remove" ]; then
4530
stop_agent_systemd

scripts/packages/preinstall.sh

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ set -e
1111
################################
1212

1313
LOG_LEVEL=""
14-
INSTANCE_GROUP=""
1514

1615
################################
1716
###### Default variables
@@ -22,43 +21,11 @@ export AGENT_GROUP="${AGENT_GROUP:-$(id -ng)}"
2221
# shellcheck source=/dev/null
2322
. /etc/os-release
2423

25-
if [ "$ID" = "freebsd" ]; then
26-
AGENT_CONFIG_FILE=${AGENT_CONFIG_FILE:-"/usr/local/etc/nginx-agent/nginx-agent.conf"}
27-
AGENT_DYNAMIC_CONFIG_DIR="/var/db/nginx-agent"
28-
# Old location of agent-dynamic.conf
29-
OLD_DYNAMIC_CONFIG_DIR="/etc/nginx-agent"
30-
mkdir -p /var/log/nginx-agent/
31-
else
32-
AGENT_CONFIG_FILE=${AGENT_CONFIG_FILE:-"/etc/nginx-agent/nginx-agent.conf"}
33-
AGENT_DYNAMIC_CONFIG_DIR="/var/lib/nginx-agent"
34-
# Old location of agent-dynamic.conf
35-
OLD_DYNAMIC_CONFIG_DIR="/etc/nginx-agent"
36-
fi
37-
38-
AGENT_DYNAMIC_CONFIG_FILE="${AGENT_DYNAMIC_CONFIG_DIR}/agent-dynamic.conf"
39-
OLD_DYNAMIC_CONFIG_FILE="${OLD_DYNAMIC_CONFIG_DIR}/agent-dynamic.conf"
40-
AGENT_DYNAMIC_CONFIG_COMMENT="#
41-
# agent-dynamic.conf
42-
#
43-
# Dynamic configuration file for NGINX Agent.
44-
#
45-
# The purpose of this file is to track NGINX Agent configuration
46-
# values that can be dynamically changed via the API and the NGINX Agent install script.
47-
# You may edit this file, but API calls that modify the tags on this system will
48-
# overwrite the tag values in this file.
49-
#
50-
# The NGINX Agent configuration values that API calls can modify are as follows:
51-
# - tags
52-
#
53-
# The NGINX Agent configuration value(s) that the NGINX Agent install script can modify are as follows:
54-
# - instance_group
55-
56-
"
24+
AGENT_CONFIG_FILE=${AGENT_CONFIG_FILE:-"/etc/nginx-agent/nginx-agent.conf"}
5725

5826
#
5927
# Functions
6028
#
61-
6229
err_exit() {
6330
printf "\n%b" "$1"
6431
printf " exiting.\n"
@@ -77,68 +44,21 @@ ensure_sudo() {
7744
fi
7845
}
7946

80-
create_config_file() {
81-
mkdir -p ${AGENT_DYNAMIC_CONFIG_DIR}
82-
printf "%s" "${AGENT_DYNAMIC_CONFIG_COMMENT}" | tee ${AGENT_DYNAMIC_CONFIG_FILE} > /dev/null
83-
chmod 0640 ${AGENT_DYNAMIC_CONFIG_FILE}
84-
printf "Successfully created %s\n" "${AGENT_DYNAMIC_CONFIG_FILE}"
85-
}
86-
87-
load_config_values() {
88-
if [ ! -f "$AGENT_DYNAMIC_CONFIG_FILE" ]; then
89-
if [ -f "$OLD_DYNAMIC_CONFIG_FILE" ]; then
90-
printf "Moving %s to %s\n" "$OLD_DYNAMIC_CONFIG_FILE" "$AGENT_DYNAMIC_CONFIG_FILE"
91-
mkdir -p ${AGENT_DYNAMIC_CONFIG_DIR}
92-
mv "$OLD_DYNAMIC_CONFIG_FILE" "$AGENT_DYNAMIC_CONFIG_FILE"
93-
printf "Creating symlink %s at %s\n" "$AGENT_DYNAMIC_CONFIG_FILE" "$OLD_DYNAMIC_CONFIG_FILE"
94-
ln -s "$AGENT_DYNAMIC_CONFIG_FILE" "$OLD_DYNAMIC_CONFIG_FILE"
95-
else
96-
printf "Could not find %s ... Creating file\n" ${AGENT_DYNAMIC_CONFIG_FILE}
97-
create_config_file
98-
fi
99-
100-
fi
101-
102-
# Check if there are existing values
103-
_instance_group="$(grep "^instance_group:" "${AGENT_DYNAMIC_CONFIG_FILE}" | head -n 1 | cut -d : -f 2 | sed "s/^[[:space:]]//")"
104-
105-
if [ "$_instance_group" ] && [ ! "${INSTANCE_GROUP}" ]; then
106-
INSTANCE_GROUP=$_instance_group
107-
fi
108-
}
109-
11047
update_config_file() {
11148
sed_cmd="sed -i.bak "
11249

113-
printf "Updating %s ...\n" "${AGENT_DYNAMIC_CONFIG_FILE}"
114-
11550
if [ ! -f "$AGENT_CONFIG_FILE" ]; then
11651
printf "NGINX Agent config file %s does not exist. Could not be updated\n" "$AGENT_CONFIG_FILE"
11752
exit 0
11853
fi
11954

120-
if [ ! -f "$AGENT_DYNAMIC_CONFIG_FILE" ]; then
121-
err_exit "$AGENT_DYNAMIC_CONFIG_FILE does not exist"
122-
fi
123-
12455
if [ "${PACKAGE_HOST}" ]; then
12556
printf "Updating %s ...\n" "${AGENT_CONFIG_FILE}"
12657

12758
# Replace Host
12859
${sed_cmd} "s/host:.*$/host: ${PACKAGE_HOST}/" "${AGENT_CONFIG_FILE}"
12960
fi
13061

131-
# Check the instance group and set accordingly
132-
if [ "${INSTANCE_GROUP}" ]; then
133-
if [ "$(grep -cP '^(?=[\s]*+[^#])[^#]*(instance_group)' "${AGENT_DYNAMIC_CONFIG_FILE}")" -ge 1 ]; then
134-
printf "Setting existing instance_group: %s\n" "${INSTANCE_GROUP}"
135-
${sed_cmd} "/^[[:space:]]*#/!s/\(instance_group:.*\)/instance_group: ${INSTANCE_GROUP}/g" "${AGENT_DYNAMIC_CONFIG_FILE}"
136-
else
137-
printf "Setting instance_group: %s\n" "${INSTANCE_GROUP}"
138-
printf "instance_group: %s\n" "${INSTANCE_GROUP}" >> "${AGENT_DYNAMIC_CONFIG_FILE}"
139-
fi
140-
printf "Successfully updated %s\n" "${AGENT_DYNAMIC_CONFIG_FILE}"
141-
fi
14262
# Check the log-level and set accordingly
14363
if [ "${LOG_LEVEL}" ]; then
14464
if [ "$(grep -cP '^(?=[\s]*+[^#])[^#]*(level:)' "${AGENT_CONFIG_FILE}")" -ge 1 ]; then
@@ -162,6 +82,5 @@ update_config_file() {
16282
{
16383
title
16484
ensure_sudo
165-
load_config_values
16685
update_config_file
16786
}

0 commit comments

Comments
 (0)