Fix handling of auto updater and data files during native package removal. (#21203)
* Make DEB packages properly clean up updater configuration and runtime data. * Properly disable autoupdates during RPM package removal. * Restructure uninstaller for better cleanup handling for native packages. * Add error handling for netdata-updater.timer shutoff. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Austin S. Hemmelgarn committed
Oct 29, 2025 at 07:55 UTC
c0721c42d0f6a588b308cf39fe4208846037d7bf
5 files changed
+70
-30
netdata.spec.in
+13
-1
@@ -538,15 +538,25 @@ done
538
%preun
539
%if 0%{?suse_version}
540
%service_del_preun %{name}.service
541
+%service_del_preun %{name}-updater.timer
542
%else
543
%systemd_preun %{name}.service
544
+%systemd_preun %{name}-updater.timer
545
%endif
546
547
+if [ "${1}" -eq 0 ]; then
548
+ if [ -x "%{_libexecdir}/%{name}/%{name}-updater.sh" ]; then
549
+ %{_libexecdir}/%{name}/%{name}-updater.sh --disable-auto-updates
550
+ fi
551
+fi
552
+
553
%postun
554
%if 0%{?suse_version}
555
%service_del_postun %{name}.service
556
+%service_del_postun %{name}-updater.timer
557
%else
558
%systemd_postun_with_restart %{name}.service
559
+%systemd_postun_with_restart %{name}-updater.timer
560
%endif
561
562
%clean
@@ -3256,7 +3266,9 @@ fi
3266
%endif
3267
3268
%changelog
3259
-* Tue Sep 30 2025 Austin Hemmelgarn <austin@netdata.cloud>
3269
+* Fri Oct 24 2025 Austin Hemmelgarn <austin@netdata.cloud> 0.0.0-36
3270
+- Add proper cleanup of auto-update configuration on uninstall
3271
+* Tue Sep 30 2025 Austin Hemmelgarn <austin@netdata.cloud> 0.0.0-35
3272
- Add IBM plugin
3273
* Tue Jul 29 2025 Austin Hemmelgarn <austin@netdata.cloud> 0.0.0-34
3274
- Add OpenTelemetry plugin
packaging/cmake/Modules/Packaging.cmake
+1
@@ -109,6 +109,7 @@ set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
109
"${PKG_FILES_PATH}/deb/netdata/conffiles;"
110
"${PKG_FILES_PATH}/deb/netdata/preinst"
111
"${PKG_FILES_PATH}/deb/netdata/postinst"
112
+ "${PKG_FILES_PATH}/deb/netdata/prerm"
113
"${PKG_FILES_PATH}/deb/netdata/postrm")
114
115
set(CPACK_DEBIAN_NETDATA_DEBUGINFO_PACKAGE Off)
packaging/cmake/pkg-files/deb/netdata/postrm
+16
-14
@@ -3,7 +3,12 @@
3
set -e
4
5
case "$1" in
6
- remove) ;;
6
+ remove)
7
+ if [ -x "/usr/bin/deb-systemd-helper" ]; then
8
+ deb-systemd-helper mask 'netdata.service' >/dev/null || true
9
+ deb-systemd-helper mask 'netdata-updater.timer' >/dev/null || true
10
+ fi
11
+ ;;
12
13
purge)
14
if dpkg-statoverride --list | grep -qw /var/cache/netdata; then
@@ -25,23 +30,20 @@ case "$1" in
30
if dpkg-statoverride --list | grep -qw /var/log/netdata; then
31
dpkg-statoverride --remove /var/log/netdata
32
fi
33
+
34
+ if [ -x "/usr/bin/deb-systemd-helper" ]; then
35
+ deb-systemd-helper purge 'netdata.service' >/dev/null || true
36
+ deb-systemd-helper unmask 'netdata.service' >/dev/null || true
37
+ deb-systemd-helper purge 'netdata-updater.timer' >/dev/null || true
38
+ deb-systemd-helper unmask 'netdata-updater.timer' >/dev/null || true
39
+ fi
40
+
41
+ rm -rf /var/cache/netdata || true
42
+ rm -rf /var/lib/netdata || true
43
;;
44
45
*) ;;
46
47
esac
48
34
-if [ "$1" = "remove" ]; then
35
- if [ -x "/usr/bin/deb-systemd-helper" ]; then
36
- deb-systemd-helper mask 'netdata.service' >/dev/null || true
37
- fi
38
-fi
39
-
40
-if [ "$1" = "purge" ]; then
41
- if [ -x "/usr/bin/deb-systemd-helper" ]; then
42
- deb-systemd-helper purge 'netdata.service' >/dev/null || true
43
- deb-systemd-helper unmask 'netdata.service' >/dev/null || true
44
- fi
45
-fi
46
-
49
exit 0
packaging/cmake/pkg-files/deb/netdata/prerm
new
+11
@@ -0,0 +1,11 @@
1
+#!/bin/sh
2
+
3
+set -e
4
+
5
+case "$1" in
6
+ remove)
7
+ if [ -x "/usr/libexec/netdata/netdata-updater.sh" ] ; then
8
+ /usr/libexec/netdata/netdata-updater.sh --disable-auto-updates
9
+ fi
10
+ ;;
11
+esac
packaging/installer/netdata-uninstaller.sh
+29
-15
@@ -229,7 +229,31 @@ pkg_installed() {
229
esac
230
}
231
232
+disable_updater() {
233
+ if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh" ]; then
234
+ "${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh" --disable-auto-updates
235
+ else
236
+ rm_file /etc/periodic/daily/netdata-updater
237
+ rm_file /etc/cron.daily/netdata-updater
238
+ rm_file /etc/cron.d/netdata-updater
239
+ rm_file /etc/cron.d/netdata-updater-daily
240
+
241
+ if command -v systemctl >/dev/null 2>&1 ; then
242
+ systemctl stop netdata-updater.timer >/dev/null 2>&1 || true
243
+ systemctl disable netdata-updater.timer >/dev/null 2>&1 || true
244
+ fi
245
+ fi
246
+}
247
+
248
+cleanup_data_and_config() {
249
+ rm_dir "${NETDATA_PREFIX}/var/lib/netdata"
250
+ rm_dir "${NETDATA_PREFIX}/var/cache/netdata"
251
+ rm_dir "${NETDATA_PREFIX}/var/log/netdata"
252
+ rm_dir "${NETDATA_PREFIX}/etc/netdata"
253
+}
254
+
255
detect_existing_install
256
+disable_updater
257
258
if [ -x "$(command -v apt-get)" ] && [ "${INSTALL_TYPE}" = "binpkg-deb" ]; then
259
if dpkg -s netdata > /dev/null; then
@@ -250,6 +274,7 @@ if [ -x "$(command -v apt-get)" ] && [ "${INSTALL_TYPE}" = "binpkg-deb" ]; then
274
apt-get remove netdata-repo ${FLAG}
275
fi
276
fi
277
+ cleanup_data_and_config
278
exit 0
279
fi
280
elif [ -x "$(command -v dnf)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then
@@ -271,6 +296,7 @@ elif [ -x "$(command -v dnf)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then
296
dnf remove netdata-repo ${FLAG}
297
fi
298
fi
299
+ cleanup_data_and_config
300
exit 0
301
fi
302
elif [ -x "$(command -v yum)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then
@@ -292,6 +318,7 @@ elif [ -x "$(command -v yum)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then
318
yum remove netdata-repo ${FLAG}
319
fi
320
fi
321
+ cleanup_data_and_config
322
exit 0
323
fi
324
elif [ -x "$(command -v zypper)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then
@@ -316,6 +343,7 @@ elif [ -x "$(command -v zypper)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then
343
zypper ${FLAG} remove netdata-repo
344
fi
345
fi
346
+ cleanup_data_and_config
347
exit 0
348
fi
349
fi
@@ -758,17 +786,6 @@ fi
786
787
#### REMOVE NETDATA FILES
788
761
-# Handle updater files first so that it doesn’t try to run while we
762
-# are uninstalling things.
763
-if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh" ]; then
764
- "${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh" --disable-auto-updates
765
-else
766
- rm_file /etc/periodic/daily/netdata-updater
767
- rm_file /etc/cron.daily/netdata-updater
768
- rm_file /etc/cron.d/netdata-updater
769
- rm_file /etc/cron.d/netdata-updater-daily
770
-fi
771
-
789
if issystemd; then
790
for unit in netdata.service netdata-updater.timer; do
791
systemctl disable "${unit}"
@@ -808,10 +825,7 @@ else
825
rm_file "/tmp/netdata-service-cmds"
826
rm_dir "${NETDATA_PREFIX}/usr/share/netdata"
827
rm_dir "${NETDATA_PREFIX}/usr/libexec/netdata"
811
- rm_dir "${NETDATA_PREFIX}/var/lib/netdata"
812
- rm_dir "${NETDATA_PREFIX}/var/cache/netdata"
813
- rm_dir "${NETDATA_PREFIX}/var/log/netdata"
814
- rm_dir "${NETDATA_PREFIX}/etc/netdata"
828
+ cleanup_data_and_config
829
fi
830
831
if [ -n "${tmpdir}" ]; then