9c7eed7edc
* Updates:
- Env variable RSMI_LOGGING=0 or any other value
-> all logging off
- Env variable RSMI_LOGGING=1 -> logs only
- Env variable RSMI_LOGGING=2 -> console only
- Env variable RSMI_LOGGING=3 -> both logs + console
- Metrics output includes hexdump of current file
and decoded metrics (functions: logHexDump
and log_gpu_metrics)
- System info gathered, now includes if system's
perceived endianness - little or big endian
helpful for viewing decoded hexdump or any
binary translation
- Added templates for printing unsigned hex
(print_unsigned_hex_and_int), unsigned integers
(print_unsigned_int), and printing both unsigned
hex and int with an optional header
(print_unsigned_hex_and_int)
- Fixed some build compile warnings/errors -
ex. doing strncpys for sku or board names
this operation is expected and needed
and for temp file writes if unsuccessful
we now properly send RSMI_STATUS_FILE_ERROR
- Fixed on RHEL 8.8/9.x logrotate does not properly
initialize
Change-Id: Ifa0f0218c9cafd0a8cd6aa8e7f94d61e9107200f
Signed-off-by: Charis Poag <Charis.Poag@amd.com>
127 строки
4.2 KiB
Bash
Исполняемый файл
127 строки
4.2 KiB
Bash
Исполняемый файл
#!/bin/bash
|
|
#set -x
|
|
|
|
packageName="rocm-smi-lib"
|
|
logPath=/var/log/rocm_smi_lib
|
|
logName=ROCm-SMI-lib.log
|
|
logFile="${logPath}/${logName}"
|
|
logrotateConfFile=/etc/logrotate.d/rocm_smi.conf
|
|
|
|
do_addLogFolder() {
|
|
sudo mkdir -p "${logPath}"
|
|
sudo touch "${logFile}"
|
|
sudo chmod -R a+rw "${logPath}"
|
|
sudo chmod a+rw "${logFile}"
|
|
}
|
|
|
|
do_configureLogrotate() {
|
|
logrotate --version &>/dev/null
|
|
if [ $? -ne 0 ]; then
|
|
echo "[WARNING] Detected logrotate is not installed."\
|
|
"$packageName logs (when turned on) will not rotate properly."
|
|
return
|
|
fi
|
|
|
|
if [ ! -f $logrotateConfFile ]; then
|
|
sudo touch "${logrotateConfFile}"
|
|
sudo chmod 644 "${logrotateConfFile}" # root r/w, all others read
|
|
# ROCm SMI logging rotation, rotates files using root user/group
|
|
# Hourly logrotation check
|
|
# Only rotates if size grew larger than 1MB
|
|
# Max of 4 rotation files, oldest will be removed
|
|
# Rotated files use date extention of ex. ROCm-SMI-lib.log.2023-05-09_16:51:42
|
|
cat << EOF | sudo tee "${logrotateConfFile}" >/dev/null
|
|
${logFile} {
|
|
su root root
|
|
hourly
|
|
missingok
|
|
notifempty
|
|
rotate 4
|
|
size 1M
|
|
copytruncate
|
|
dateext
|
|
dateformat .%%Y-%%m-%%d_%H:%%M:%%S
|
|
}
|
|
EOF
|
|
# Fix for % S argument not found (now we escape with %%)
|
|
# issue was RPM build thought we were using macros
|
|
# https://gitlab.kitware.com/cmake/cmake/-/issues/22965
|
|
# https://rpm-software-management.github.io/rpm/manual/spec.html
|
|
sudo sed -i s/%%/%/g "${logrotateConfFile}"
|
|
# workaround: remove extra 'OURCE' text
|
|
# from rocm_smi.conf. Unsure if CMAKE,
|
|
# bash, or here document
|
|
# issue (only seen on RHEL 8.7)
|
|
sudo sed -i s/OURCE//g "${logrotateConfFile}"
|
|
fi
|
|
# check if logrotate uses system timers, Ubuntu/modern OS's do
|
|
# Several older OS's like RHEL 8.7, do not. Instead defaults
|
|
# to use daily cron jobs - see https://stackoverflow.com/a/69465677
|
|
sudo systemctl list-timers|grep -iq logrotate
|
|
if [ $? -ne 0 ]; then
|
|
# confirm logrotate file exists in daily
|
|
if [ -f /etc/cron.daily/logrotate ]; then
|
|
# move logrotate daily to hourly
|
|
if [ -d /etc/cron.hourly ]; then
|
|
sudo mv /etc/cron.daily/logrotate /etc/cron.hourly/logrotate
|
|
else
|
|
echo "[WARNING] Could find and configure hourly cron for $packageName's"\
|
|
" logrotate. $packageName logs (when turned on) will not rotate properly."
|
|
fi
|
|
else
|
|
# confirm that it's already been moved to hourly
|
|
sudo find /etc/cron.* -iname logrotate -print -quit |grep -iq hourly
|
|
if [ $? -ne 0 ]; then
|
|
echo "[WARNING] Could not configure an hourly cron for $packageName's logrotate."\
|
|
"$packageName logs (when turned on) may not rotate properly."
|
|
fi
|
|
fi
|
|
return #done configuring for non-systemd timers
|
|
else
|
|
# Configure systemd timers - the typical setup for modern Linux logrotation setups
|
|
if [ -f /lib/systemd/system/logrotate.timer ]; then
|
|
if [ ! -f /lib/systemd/system/logrotate.timer.backup ]; then
|
|
sudo cp /lib/systemd/system/logrotate.timer /lib/systemd/system/logrotate.timer.backup
|
|
fi
|
|
cat <<'EOF' | sudo tee /lib/systemd/system/logrotate.timer >/dev/null
|
|
[Unit]
|
|
Description=Hourly rotation of log files
|
|
Documentation=man:logrotate(8) man:logrotate.conf(5)
|
|
|
|
[Timer]
|
|
OnCalendar=
|
|
OnCalendar=hourly
|
|
AccuracySec=1m
|
|
Persistent=true
|
|
|
|
[Install]
|
|
WantedBy=timers.target
|
|
EOF
|
|
sudo systemctl reenable --now logrotate.timer
|
|
else
|
|
echo "[WARNING] Could not configure systemd timer for $packageName's logrotate."\
|
|
"$packageName logs (when turned on) will not rotate properly."
|
|
fi
|
|
return #done configuring for systemd timers
|
|
fi
|
|
}
|
|
|
|
do_ldconfig() {
|
|
# left-hand term originates from ENABLE_LDCONFIG = ON/OFF at package build
|
|
if [ "@ENABLE_LDCONFIG@" == "ON" ]; then
|
|
echo @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ > /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf
|
|
ldconfig
|
|
fi
|
|
}
|
|
|
|
# left-hand term originates from ENABLE_LDCONFIG = ON/OFF at package build
|
|
if [ "@ENABLE_LDCONFIG@" == "ON" ]; then
|
|
echo -e "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@" > /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf
|
|
ldconfig
|
|
fi
|
|
|
|
# post install or upgrade, $i is 1 or 2 -> do these actions
|
|
if [ $1 -ge 1 ]; then
|
|
do_addLogFolder
|
|
do_configureLogrotate
|
|
fi |