Skip to content

Commit d42a0c8

Browse files
committed
metrics.sh: Reinstall metrics when upgrading
- Upgrade ncp-metrics-exporter to v1.1.0 - Install prometheus-node-exporter-collectors when dist-upgrading from buster Signed-off-by: Tobias K <6317548+theCalcaholic@users.noreply.github.com>
1 parent fa0fbff commit d42a0c8

File tree

5 files changed

+57
-29
lines changed

5 files changed

+57
-29
lines changed

bin/ncp-dist-upgrade

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ sleep 2 # avoid systemd thinking that PHP is in a crash/restart loop
8989
$APTINSTALL -t ${release_new} php${php_ver_new}-gmp
9090
#$APTINSTALL -t ${release_new} imagemagick php${php_ver_new}-imagick ghostscript
9191

92+
# Reinstall prometheus-node-exporter, specifically WITH install-recommends to include collectors on bullseye and later
93+
{ dpkg -l | grep '^ii.*prometheus-node-exporter' >/dev/null && apt-get install -y prometheus-node-exporter-collectors; } || true
94+
9295
apt-get autoremove -y
9396
apt-get clean
9497

bin/ncp/BACKUPS/nc-backup-auto.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ tmpl_get_destination() {
1414
)
1515
}
1616

17-
is_active() {
18-
[[ $ACTIVE == "yes" ]]
19-
}
20-
2117
configure()
2218
{
2319
[[ $ACTIVE != "yes" ]] && {

bin/ncp/SYSTEM/metrics.sh

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
22

3+
apt_install_with_recommends() {
4+
apt-get update --allow-releaseinfo-change
5+
DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::="--force-confold" "$@"
6+
}
7+
38
is_supported() {
49
[[ "$DOCKERBUILD" == 1 ]] && [[ "$(lsb_release -r)" =~ .*10 ]] && return 1
510
return 0
@@ -84,13 +89,12 @@ ARGS="--collector.filesystem.ignored-mount-points=\"^/(dev|proc|run|sys|mnt|var/
8489
EOF
8590

8691
arch="$(uname -m)"
87-
[[ "$arch" =~ ("arm"|"aarch").* ]] && bin_arch="armv7" || bin_arch="i686"
88-
[[ "$(lsb_release -r)" =~ .*10 ]] && gcclib="lib32gcc1" || gcclib="lib32gcc-s1"
89-
[[ "$arch" == "x86_64" ]] && apt_install "$gcclib" libc6-i386
92+
[[ "${arch}" =~ ^"arm" ]] && arch="armv7"
9093

91-
wget -O "/usr/local/bin/ncp-metrics-exporter" \
92-
"https://github.com/theCalcaholic/ncp-metrics-exporter/releases/download/v1.0.0/${bin_arch}-ncp-metrics-exporter"
93-
chmod +x /usr/local/bin/ncp-metrics-exporter
94+
mkdir -p /usr/local/lib/ncp-metrics
95+
wget -O "/usr/local/lib/ncp-metrics/ncp-metrics-exporter" \
96+
"https://github.com/theCalcaholic/ncp-metrics-exporter/releases/download/v1.1.0/ncp-metrics-exporter-${arch}"
97+
chmod +x /usr/local/lib/ncp-metrics/ncp-metrics-exporter
9498

9599
# Apply fix to init-d-script (https://salsa.debian.org/debian/sysvinit/-/commit/aa40516c)
96100
# Otherwise the init.d scripts of prometheus-node-exporter won't work
@@ -104,12 +108,12 @@ EOF
104108
trap "mv /etc/shadow /data/etc/shadow; ln -s /data/etc/shadow /etc/shadow" EXIT
105109
rm /etc/shadow
106110
cp /data/etc/shadow /etc/shadow
107-
apt_install prometheus-node-exporter prometheus-node-exporter-collectors
111+
apt_install_with_recommends prometheus-node-exporter
108112
mv /etc/shadow /data/etc/shadow
109113
ln -s /data/etc/shadow /etc/shadow
110114
trap - EXIT
111115
else
112-
apt_install prometheus-node-exporter prometheus-node-exporter-collectors
116+
apt_install_with_recommends prometheus-node-exporter
113117
fi
114118

115119
if [[ "$DOCKERBUILD" == 1 ]]
@@ -134,7 +138,7 @@ NCP_CONFIG_DIR=/usr/local/etc
134138
set +a
135139
136140
NAME=ncp-exporter
137-
DAEMON=/usr/local/bin/ncp-metrics-exporter
141+
DAEMON=/usr/local/lib/ncp-metrics/ncp-metrics-exporter
138142
PIDFILE=/var/run/ncp-metrics-exporter.pid
139143
LOGFILE=/var/log/ncp-metrics.log
140144
START_ARGS="--background --make-pidfile"
@@ -173,7 +177,7 @@ Description=NCP Metrics Exporter
173177
174178
[Service]
175179
Environment=NCP_CONFIG_DIR=/usr/local/etc
176-
ExecStart=/usr/local/bin/ncp-metrics-exporter
180+
ExecStart=/usr/local/lib/ncp-metrics/ncp-metrics-exporter
177181
SyslogIdentifier=ncp-metrics
178182
Restart=on-failure
179183
RestartSec=30
@@ -218,19 +222,22 @@ configure() {
218222
return 1
219223
}
220224

221-
[[ -n "$PASSWORD" ]] || {
222-
echo -e "ERROR: Password can not be empty!" >&2
223-
return 1
224-
}
225+
if [[ "$METRICS_SKIP_PASSWORD_CONFIG" != "true" ]]
226+
then
227+
[[ -n "$PASSWORD" ]] || {
228+
echo -e "ERROR: Password can not be empty!" >&2
229+
return 1
230+
}
225231

226-
[[ ${#PASSWORD} -ge 10 ]] || {
227-
echo -e "ERROR: Password must be at least 10 characters long!" >&2
228-
return 1
229-
}
232+
[[ ${#PASSWORD} -ge 10 ]] || {
233+
echo -e "ERROR: Password must be at least 10 characters long!" >&2
234+
return 1
235+
}
230236

231-
local htpasswd_file="/usr/local/etc/metrics.htpasswd"
232-
rm -f "${htpasswd_file}"
233-
echo "$PASSWORD" | htpasswd -ciB "${htpasswd_file}" "$USER"
237+
local htpasswd_file="/usr/local/etc/metrics.htpasswd"
238+
rm -f "${htpasswd_file}"
239+
echo "$PASSWORD" | htpasswd -ciB "${htpasswd_file}" "$USER"
240+
fi
234241

235242
echo "Generate config..."
236243
reload_metrics_config
@@ -252,7 +259,7 @@ configure() {
252259
return 1
253260
}
254261

255-
echo "Metrics endpoint enabled. You can test it at https://nextcloudpi.local/metrics/system (or under your NC domain under the same path)"
262+
echo "Metrics endpoint enabled. You can test it at https://nextcloudpi.local/metrics/system and https://nextcloudpi.local/metrics/ncp (or under your NC domain under the same paths)"
256263
fi
257264

258265
bash -c "sleep 2 && service apache2 reload" &>/dev/null &

changelog.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11

2-
[v1.46.10](https://github.com/nextcloud/nextcloudpi/commit/c076cb3) (2022-03-26) dnsmasq.sh: Workaround dnsmasq startup failure bug
2+
[v1.47.0](https://github.com/nextcloud/nextcloudpi/commit/1ce2135) (2022-04-08) metrics.sh: Reinstall metrics when upgrading
33

4-
[v1.46.9](https://github.com/nextcloud/nextcloudpi/commit/cd98b50) (2022-03-07) docker: adjust PHP version in apache config
4+
[v1.46.10](https://github.com/nextcloud/nextcloudpi/commit/99a3c45) (2022-03-26) dnsmasq.sh: Workaround dnsmasq startup failure bug
5+
6+
[v1.46.9 ](https://github.com/nextcloud/nextcloudpi/commit/cd98b50) (2022-03-07) docker: adjust PHP version in apache config
57

68
[v1.46.8 ](https://github.com/nextcloud/nextcloudpi/commit/21b7fe7) (2022-03-04) SSH: cannot check for default password because of Debian bug #1003151
79

@@ -193,7 +195,7 @@
193195

194196
[v1.37.0 ](https://github.com/nextcloud/nextcloudpi/commit/effdd6c) (2021-07-03) upgrade to NC20.0.11
195197

196-
[v1.36.3 ](https://github.com/nextcloud/nextcloudpi/commit/7b809d1) (2021-05-13) ncp-web: fix port checking for IPv6 dual stack
198+
[v1.36.3, master](https://github.com/nextcloud/nextcloudpi/commit/7b809d1) (2021-05-13) ncp-web: fix port checking for IPv6 dual stack
197199

198200
[v1.36.2 ](https://github.com/nextcloud/nextcloudpi/commit/1a8ac71) (2021-05-11) ncp-web: fix port checking
199201

updates/1.47.0.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Stop metrics services if running
6+
for svc in prometheus-node-exporter ncp-metrics-exporter
7+
do
8+
service "$svc" status || [[ $? -ne 4 ]] || continue
9+
service "$svc" stop
10+
done
11+
12+
# Reinstall metrics services
13+
source /usr/local/etc/library.sh
14+
install_app metrics
15+
is_active_app metrics && (
16+
export METRICS_SKIP_PASSWORD_CONFIG=true
17+
run_app metrics
18+
)
19+
20+
exit 0

0 commit comments

Comments
 (0)