From 23143abbcad13070b824e7c48fe7ceb7061dc125 Mon Sep 17 00:00:00 2001 From: Enzo Candotti Date: Fri, 6 Oct 2023 15:45:30 -0300 Subject: [PATCH] Update crashDumpMgr to source config from envfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates the crashDumpMgr service in order to: - Cleanup of current service naming and packaging to follow the standard Linux naming convention: - Repackage /etc/init.d/crashDumpMgr to /usr/sbin/crash-dump-manager - Rename crashDumpMgr.service to crash-dump-manager.service - Add EnvironmentFile to crash-dump-manager service file to source configuration from /etc/default/crash-dump-manager. - Update ExecStart of crash-dump-manager service to use parameters from EnvironmentFile - Update crash-dump-manager service dependencies to run after config.service. - Update logrotate configuration to support the retention polices of the maximum files. The “rotate 1” option was removed to permit crash-dump-manager to manage pruning old files. - Modify the crash-dump-manager script to enable updates to the max_files parameter to a lower value. If there are currently more files than the new max_files value, the oldest files will be deleted the next time a crash dump file needs to be stored, thus adhering to the new max_files values. Test Plan: PASS: Build ISO and perform a fresh install. Verify the new crash-dump-manager service is enabled and working as expected. PASS: Add and apply new crashdump service parameters and force a kernel panic. Verify that after the reboot, the max_files, max_used, min_available and max_size values are updated accordingly to the service parameters values. PASS: Verify that the crashdump files are rotated as expected. Story: 2010893 Task: 48910 Change-Id: I4a81fcc6ba456a0d73067b77588ee4a125e44e62 Signed-off-by: Enzo Candotti --- mtce/centos/mtce.spec | 10 +++--- .../deb_folder/crash-dump-manager.service | 14 ++++++++ mtce/debian/deb_folder/crashDumpMgr.service | 12 ------- mtce/debian/deb_folder/mtce.install | 4 ++- mtce/debian/deb_folder/rules | 9 +++-- mtce/src/scripts/55-crash-dump-manager.preset | 1 + .../{crashDumpMgr => crash-dump-manager} | 33 +++++++++++++------ mtce/src/scripts/crash-dump-manager.service | 13 ++++++++ mtce/src/scripts/crash-dump-manager_envfile | 4 +++ mtce/src/scripts/crashDumpMgr.service | 12 ------- mtce/src/scripts/crashdump.logrotate | 6 ++-- 11 files changed, 72 insertions(+), 46 deletions(-) create mode 100644 mtce/debian/deb_folder/crash-dump-manager.service delete mode 100644 mtce/debian/deb_folder/crashDumpMgr.service create mode 100644 mtce/src/scripts/55-crash-dump-manager.preset rename mtce/src/scripts/{crashDumpMgr => crash-dump-manager} (89%) create mode 100644 mtce/src/scripts/crash-dump-manager.service create mode 100644 mtce/src/scripts/crash-dump-manager_envfile delete mode 100644 mtce/src/scripts/crashDumpMgr.service diff --git a/mtce/centos/mtce.spec b/mtce/centos/mtce.spec index 04bd9940..9903847a 100644 --- a/mtce/centos/mtce.spec +++ b/mtce/centos/mtce.spec @@ -350,8 +350,8 @@ install -m 700 -p -D %{_buildsubdir}/alarm/scripts/mtcalarm.init %{buildroot}%{_ # TODO: Init hack. Should move to proper module install -m 755 -p -D %{_buildsubdir}/scripts/hwclock.sh %{buildroot}%{_sysconfdir}/init.d/hwclock.sh install -m 644 -p -D %{_buildsubdir}/scripts/hwclock.service %{buildroot}%{_unitdir}/hwclock.service -install -m 755 -p -D %{_buildsubdir}/scripts/crashDumpMgr %{buildroot}%{_sysconfdir}/init.d/crashDumpMgr -install -m 644 -p -D %{_buildsubdir}/scripts/crashDumpMgr.service %{buildroot}%{_unitdir}/crashDumpMgr.service +install -m 755 -p -D %{_buildsubdir}/scripts/crash-dump-manager %{buildroot}%{_sysconfdir}/init.d/crash-dump-manager +install -m 644 -p -D %{_buildsubdir}/scripts/crash-dump-manager.service %{buildroot}%{_unitdir}/crash-dump-manager.service # systemd service files install -m 644 -p -D %{_buildsubdir}/fsmon/scripts/fsmon.service %{buildroot}%{_unitdir}/fsmon.service @@ -435,7 +435,7 @@ install -m 755 -d %{buildroot}/var/run /bin/systemctl enable rsyncd.service /bin/systemctl enable goenabled.service /bin/systemctl enable mtcalarm.service -/bin/systemctl enable crashDumpMgr.service +/bin/systemctl enable crash-dump-manager.service %post -n mtce-hostw /bin/systemctl enable hostw.service @@ -509,7 +509,7 @@ install -m 755 -d %{buildroot}/var/run %{_sysconfdir}/init.d/mtcClient %{_sysconfdir}/init.d/mtcalarm %{_sysconfdir}/init.d/hwclock.sh -%{_sysconfdir}/init.d/crashDumpMgr +%{_sysconfdir}/init.d/crash-dump-manager %{_unitdir}/runservices.service %{_unitdir}/goenabled.service @@ -519,7 +519,7 @@ install -m 755 -d %{buildroot}/var/run %{_unitdir}/mtcClient.service %{_unitdir}/hbsClient.service %{_unitdir}/hwclock.service -%{_unitdir}/crashDumpMgr.service +%{_unitdir}/crash-dump-manager.service # Binaries %{local_bindir}/mtcAgent diff --git a/mtce/debian/deb_folder/crash-dump-manager.service b/mtce/debian/deb_folder/crash-dump-manager.service new file mode 100644 index 00000000..0b1dcf88 --- /dev/null +++ b/mtce/debian/deb_folder/crash-dump-manager.service @@ -0,0 +1,14 @@ +[Unit] +Description=Crash Dump Manager +After=network.target config.target +Before=sshd.service +DefaultEnabled=true + +[Service] +Type=oneshot +RemainAfterExit=no +EnvironmentFile=/etc/default/crash-dump-manager +ExecStart=/usr/sbin/crash-dump-manager --max-size $MAX_SIZE --max-files $MAX_FILES --max-used $MAX_USED --min-available $MIN_AVAILABLE + +[Install] +WantedBy=multi-user.target diff --git a/mtce/debian/deb_folder/crashDumpMgr.service b/mtce/debian/deb_folder/crashDumpMgr.service deleted file mode 100644 index bec36c04..00000000 --- a/mtce/debian/deb_folder/crashDumpMgr.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Crash Dump Manager -After=network.target -Before=sshd.service - -[Service] -Type=oneshot -RemainAfterExit=no -ExecStart=/etc/init.d/crashDumpMgr --max-size 5Gi - -[Install] -WantedBy=multi-user.target diff --git a/mtce/debian/deb_folder/mtce.install b/mtce/debian/deb_folder/mtce.install index 3a6dd360..b30cf33e 100644 --- a/mtce/debian/deb_folder/mtce.install +++ b/mtce/debian/deb_folder/mtce.install @@ -2,7 +2,7 @@ etc/bmc/server_profiles.d/sensor_hp360_v1_ilo_v4.profile etc/bmc/server_profiles.d/sensor_hp380_v1_ilo_v4.profile etc/bmc/server_profiles.d/sensor_quanta_v1_ilo_v4.profile etc/collect.d/collect_bmc -etc/init.d/crashDumpMgr +etc/default/crash-dump-manager etc/init.d/fsmon etc/init.d/goenabled etc/init.d/hbsClient @@ -22,6 +22,7 @@ etc/services.d/controller/mtcTest etc/services.d/storage/mtcTest etc/services.d/worker/mtcTest etc/syslog-ng/conf.d/mtce.conf +etc/systemd/system-preset/ usr/lib/ocf/resource.d/platform/mtcAgent usr/local/bin/fsmond usr/local/bin/hbsAgent @@ -31,6 +32,7 @@ usr/local/bin/mtcClient usr/local/bin/mtcalarmd usr/local/bin/mtclogd usr/local/bin/wipedisk +usr/sbin/crash-dump-manager usr/sbin/dmemchk.sh usr/sbin/fsync usr/share/mtce/hwclock.service diff --git a/mtce/debian/deb_folder/rules b/mtce/debian/deb_folder/rules index d377ffd7..3929f924 100644 --- a/mtce/debian/deb_folder/rules +++ b/mtce/debian/deb_folder/rules @@ -36,6 +36,7 @@ override_dh_auto_install: # Configuration files install -m 600 -p -D scripts/mtc.ini $(SYSCONFDIR)/mtc.ini + install -m 600 -p -D scripts/crash-dump-manager_envfile $(SYSCONFDIR)/default/crash-dump-manager install -m 600 -p -D scripts/mtc.conf $(SYSCONFDIR)/mtc.conf install -m 600 -p -D fsmon/scripts/fsmond.conf $(SYSCONFDIR)/mtc/fsmond.conf install -m 600 -p -D hwmon/scripts/hwmond.conf $(SYSCONFDIR)/mtc/hwmond.conf @@ -65,13 +66,13 @@ override_dh_auto_install: install -m 755 -d $(SBINDIR) install -m 700 -p -D fsync/fsync $(SBINDIR)/fsync install -m 755 -d $(SBINDIR) + install -m 755 -p -D scripts/crash-dump-manager $(SBINDIR)/crash-dump-manager install -m 700 -p -D pmon/scripts/pmon-restart $(LOCAL_SBINDIR)/pmon-restart install -m 700 -p -D pmon/scripts/pmon-start $(LOCAL_SBINDIR)/pmon-start install -m 700 -p -D pmon/scripts/pmon-stop $(LOCAL_SBINDIR)/pmon-stop # init script files install -m 755 -d $(INITDIR) - install -m 755 -p -D scripts/crashDumpMgr $(INITDIR)/crashDumpMgr install -m 700 -p -D scripts/mtcClient $(INITDIR)/mtcClient install -m 700 -p -D scripts/hbsClient $(INITDIR)/hbsClient install -m 700 -p -D hwmon/scripts/lsb/hwmon $(INITDIR)/hwmon @@ -148,8 +149,12 @@ override_dh_auto_install: install -m 755 -d $(ROOT)/var install -m 755 -d $(ROOT)/var/run + # Presets + install -d $(SYSCONFDIR)/systemd/system-preset + install -m 544 scripts/55-crash-dump-manager.preset $(SYSCONFDIR)/systemd/system-preset + override_dh_installsystemd: - dh_installsystemd --name crashDumpMgr + dh_installsystemd --name crash-dump-manager dh_installsystemd --name fsmon dh_installsystemd --name goenabled dh_installsystemd --name hbsClient diff --git a/mtce/src/scripts/55-crash-dump-manager.preset b/mtce/src/scripts/55-crash-dump-manager.preset new file mode 100644 index 00000000..e0949dd2 --- /dev/null +++ b/mtce/src/scripts/55-crash-dump-manager.preset @@ -0,0 +1 @@ +enable crash-dump-manager.service diff --git a/mtce/src/scripts/crashDumpMgr b/mtce/src/scripts/crash-dump-manager similarity index 89% rename from mtce/src/scripts/crashDumpMgr rename to mtce/src/scripts/crash-dump-manager index a59ec9a9..794a4e2a 100644 --- a/mtce/src/scripts/crashDumpMgr +++ b/mtce/src/scripts/crash-dump-manager @@ -5,7 +5,7 @@ # SPDX-License-Identifier: Apache-2.0 # -CRASHDUMPMGR_TAG=${CRASHDUMPMGR_TAG:-"crashDumpMgr"} +CRASHDUMPMGR_TAG=${CRASHDUMPMGR_TAG:-"crash-dump-manager"} RETVAL=0 @@ -13,6 +13,7 @@ RETVAL=0 DEFAULT_MAX_SIZE=5368709120 # "5GiB" DEFAULT_MAX_FILES=4 UNLIMITED="unlimited" +DEFAULT="default" DEFAULT_MAX_USED="${UNLIMITED}" # Assign UNLIMITED to DEFAULT_MAX_USED DEFAULT_MIN_REMAINDER_PERCENT=10 MIN_REMAINDER_MINIMUM=1073741824 # 1GiB in bytes @@ -141,9 +142,15 @@ function manage_crash_dumps() vmcore_size_hr=$(${NUMFMT_TO_HR} ${vmcore_size}) # Manage max number of files - if [ "$(ls -A ${CRASH_BUNDLE_DIR} | wc -l)" -ge "${max_files}" ]; then - oldest_vmcore=$(ls -t ${CRASH_BUNDLE_DIR} | tail -2 | head -1) - oldest_vmcore_size=$(stat --format='%s' ${oldest_vmcore}) + files_in_crash_bundle_dir=$(ls -A ${CRASH_BUNDLE_DIR} | wc -l) + num_files_to_remove=$((files_in_crash_bundle_dir-max_files+1)) + + if [ "${num_files_to_remove}" -ge 1 ]; then + files_to_remove=$(ls -t ${CRASH_BUNDLE_DIR} | tail -$((num_files_to_remove+1)) | head -$((num_files_to_remove))) + files_to_remove_size=0 + for file in ${files_to_remove}; do + files_to_remove_size+=$(stat --format='%s' ${file}) + done max_files_saved=true fi @@ -156,8 +163,8 @@ function manage_crash_dumps() # if the ${CRASH_BUNDLE_DIR} contains the maximum number of files, the available and used_space # need to be updated to the value after deleting the oldest crash dump file. if [ "${max_files_saved}" = true ] ; then - available=$((available+oldest_vmcore_size)) - used_space=$((used_space-oldest_vmcore_size)) + available=$((available+files_to_remove_size)) + used_space=$((used_space-files_to_remove_size)) fi available_hr=$(${NUMFMT_TO_HR} ${available}) log "new vmcore detected (size:${vmcore_size}:${vmcore_size_hr}) ;" \ @@ -194,9 +201,11 @@ function manage_crash_dumps() else if [ "${max_files_saved}" = true ] ; then - # delete oldest vmcore file - log "removing oldest vmcore file: ${oldest_vmcore}" - rm -rf "${CRASH_BUNDLE_DIR}/${oldest_vmcore}" + for file in ${files_to_remove}; do + # delete old vmcore file + log "removing old vmcore file: ${file}" + rm -rf "${CRASH_BUNDLE_DIR}/${file}" + done fi log "creating bundle from ${entry}" ${IONICE_CMD} ${NICE_CMD} ${TAR_CMD} ${OTHER_BUNDLE}_${time}.tar -C ${CRASH_DIR} $(basename ${entry}) @@ -284,7 +293,11 @@ while [[ $# -gt 0 ]]; do --min-available) shift - min_available=$(${NUMFMT_FROM_HR} "$(normalize_size_format "${1}")") + if [ "${1}" = "${DEFAULT}" ]; then + min_available="" + else + min_available=$(${NUMFMT_FROM_HR} "$(normalize_size_format "${1}")") + fi shift ;; diff --git a/mtce/src/scripts/crash-dump-manager.service b/mtce/src/scripts/crash-dump-manager.service new file mode 100644 index 00000000..8cc78c89 --- /dev/null +++ b/mtce/src/scripts/crash-dump-manager.service @@ -0,0 +1,13 @@ +[Unit] +Description=Crash Dump Manager +After=network.target config.target +Before=sshd.service + +[Service] +Type=oneshot +RemainAfterExit=no +EnvironmentFile=/etc/default/crash-dump-manager +ExecStart=/usr/sbin/crash-dump-manager --max-size $MAX_SIZE --max-files $MAX_FILES --max-used $MAX_USED --min-available $MIN_AVAILABLE + +[Install] +WantedBy=multi-user.target diff --git a/mtce/src/scripts/crash-dump-manager_envfile b/mtce/src/scripts/crash-dump-manager_envfile new file mode 100644 index 00000000..6edab554 --- /dev/null +++ b/mtce/src/scripts/crash-dump-manager_envfile @@ -0,0 +1,4 @@ +MAX_FILES=4 +MAX_SIZE=5Gi +MAX_USED=unlimited +MIN_AVAILABLE=default diff --git a/mtce/src/scripts/crashDumpMgr.service b/mtce/src/scripts/crashDumpMgr.service deleted file mode 100644 index bec36c04..00000000 --- a/mtce/src/scripts/crashDumpMgr.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Crash Dump Manager -After=network.target -Before=sshd.service - -[Service] -Type=oneshot -RemainAfterExit=no -ExecStart=/etc/init.d/crashDumpMgr --max-size 5Gi - -[Install] -WantedBy=multi-user.target diff --git a/mtce/src/scripts/crashdump.logrotate b/mtce/src/scripts/crashdump.logrotate index ca8e84c6..c8fa0fe4 100644 --- a/mtce/src/scripts/crashdump.logrotate +++ b/mtce/src/scripts/crashdump.logrotate @@ -1,14 +1,12 @@ # -# Copyright (c) 2020-2021 Wind River Systems, Inc. +# Copyright (c) 2020-2021,2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 -/var/log/crash/vmcore.tar -/var/log/crash/vmcore_first.tar +/var/log/crash/vmcore_*.tar { size 1K start 1 - rotate 1 missingok notifempty compress