Skip to content

Commit 907fd2c

Browse files
committed
chore: remove unsupported from agent v3 install
1 parent 0024261 commit 907fd2c

File tree

2 files changed

+16
-127
lines changed

2 files changed

+16
-127
lines changed

scripts/packages/postinstall.sh

Lines changed: 15 additions & 46 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,17 +151,12 @@ 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
176154
}
177155

178156
add_default_config_file() {
179-
if [ ! -f "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf ]; then
157+
if [ ! -f /etc/nginx-agent/nginx-agent.conf ]; then
180158
printf "PostInstall: Creating default nginx-agent.conf file\n"
181-
cat <<EOF > "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf
159+
cat <<EOF > /etc/nginx-agent/nginx-agent.conf
182160
#
183161
# /etc/nginx-agent/nginx-agent.conf
184162
#
@@ -249,37 +227,33 @@ api:
249227
port: 8081
250228
EOF
251229
printf "PostInstall: Updating file permissions for nginx-agent.conf to 0640\n"
252-
chmod 0640 "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf
230+
chmod 0640 /etc/nginx-agent/nginx-agent.conf
253231
fi
254232
}
255233

256234
upgrade_config_file() {
257-
if [ -f "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf ]; then
235+
if [ -f /etc/nginx-agent/nginx-agent.conf ]; then
258236
extensions=""
259-
if grep -q "advanced_metrics:" "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf; then
237+
if grep -q "advanced_metrics:" /etc/nginx-agent/nginx-agent.conf; then
260238
extensions="${extensions} advanced-metrics"
261239
fi
262-
if grep -q "nginx_app_protect:" "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf; then
240+
if grep -q "nginx_app_protect:" /etc/nginx-agent/nginx-agent.conf; then
263241
extensions="${extensions} nginx-app-protect"
264242
fi
265-
if grep -q "nap_monitoring:" "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf; then
243+
if grep -q "nap_monitoring:" /etc/nginx-agent/nginx-agent.conf; then
266244
extensions="${extensions} nap-monitoring"
267245
fi
268-
if ! grep -q "extensions:" "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf && [ "${#extensions}" -ne "0" ]; then
246+
if ! grep -q "extensions:" /etc/nginx-agent/nginx-agent.conf && [ "${#extensions}" -ne "0" ]; then
269247
printf "PostInstall: Updating nginx-agent.conf to include extensions array\n"
270-
printf "\nextensions:\n" >> "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf
248+
printf "\nextensions:\n" >> /etc/nginx-agent/nginx-agent.conf
271249
for extension in ${extensions}; do
272-
echo " - $extension" >> "${BSD_HIER}"/etc/nginx-agent/nginx-agent.conf
250+
echo " - $extension" >> /etc/nginx-agent/nginx-agent.conf
273251
done
274252
fi
275253
fi
276254
}
277255

278256
restart_agent_if_required() {
279-
if [ "${ID}" = "freebsd" ]; then
280-
# https://github.com/freebsd/pkg/pull/2128
281-
return
282-
fi
283257
if service nginx-agent status >/dev/null 2>&1; then
284258
printf "PostInstall: Restarting nginx agent\n"
285259
service nginx-agent restart || true
@@ -291,15 +265,10 @@ summary() {
291265
echo " NGINX Agent package has been successfully installed."
292266
echo ""
293267
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
268+
echo " sudo systemctl start nginx-agent"
269+
echo ""
301270
echo " Configuration settings can be adjusted here:"
302-
echo " ${BSD_HIER}/etc/nginx-agent/nginx-agent.conf"
271+
echo " /etc/nginx-agent/nginx-agent.conf"
303272
echo ""
304273
echo "----------------------------------------------------------------------"
305274
}

scripts/packages/preinstall.sh

Lines changed: 1 addition & 81 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,38 +21,7 @@ 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
@@ -77,68 +45,21 @@ ensure_sudo() {
7745
fi
7846
}
7947

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-
11048
update_config_file() {
11149
sed_cmd="sed -i.bak "
11250

113-
printf "Updating %s ...\n" "${AGENT_DYNAMIC_CONFIG_FILE}"
114-
11551
if [ ! -f "$AGENT_CONFIG_FILE" ]; then
11652
printf "NGINX Agent config file %s does not exist. Could not be updated\n" "$AGENT_CONFIG_FILE"
11753
exit 0
11854
fi
11955

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

12759
# Replace Host
12860
${sed_cmd} "s/host:.*$/host: ${PACKAGE_HOST}/" "${AGENT_CONFIG_FILE}"
12961
fi
13062

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
14263
# Check the log-level and set accordingly
14364
if [ "${LOG_LEVEL}" ]; then
14465
if [ "$(grep -cP '^(?=[\s]*+[^#])[^#]*(level:)' "${AGENT_CONFIG_FILE}")" -ge 1 ]; then
@@ -162,6 +83,5 @@ update_config_file() {
16283
{
16384
title
16485
ensure_sudo
165-
load_config_values
16686
update_config_file
16787
}

0 commit comments

Comments
 (0)