Skip to content

Commit

Permalink
Merge pull request #201 from mssonicbld/sonicbld/202305-merge
Browse files Browse the repository at this point in the history
[code sync] Merge code from sonic-net/sonic-buildimage:202305 to 202305
  • Loading branch information
mssonicbld authored Dec 27, 2023
2 parents 4e1ce78 + 4f47de5 commit 0baa641
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 5 deletions.
12 changes: 8 additions & 4 deletions files/initramfs-tools/fsck-rootfs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ root_val=""
set -- $(cat /proc/cmdline)
for x in "$@"; do
case "$x" in
root=UUID=*)
root_val="${x#root=UUID=}"
blkdev=$(blkid --uuid $root_val)
;;
root=*)
root_val="${x#root=}"
blkdev="${x#root=}"
;;
esac
done

# Check the filesystem we are using
if [ ! -z $root_val ]; then
fstype=$(blkid -o value -s TYPE $root_val)
if [ ! -z $blkdev ]; then
fstype=$(blkid -o value -s TYPE $blkdev)
case "$fstype" in
ext4)
cmd="fsck.ext4 -v -p"
Expand All @@ -29,6 +33,6 @@ if [ ! -z $root_val ]; then
;;
esac
if [ ! -z "$cmd" ]; then
$cmd $root_val 2>&1 | gzip -c > /tmp/fsck.log.gz
$cmd $blkdev 2>&1 | gzip -c > /tmp/fsck.log.gz
fi
fi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
haliburton/cfg/haliburton-modules.conf etc/modules-load.d
haliburton/systemd/platform-modules-haliburton.service lib/systemd/system
haliburton/systemd/cpu_wdt.service lib/systemd/system
haliburton/script/fancontrol.sh etc/init.d
haliburton/script/fancontrol.service lib/systemd/system
services/fancontrol/fancontrol usr/local/bin
Expand All @@ -8,4 +9,5 @@ services/platform_api/platform_api_mgnt.sh usr/local/bin
haliburton/script/popmsg.sh usr/local/bin
haliburton/script/udev_prefix.sh usr/local/bin
haliburton/script/reload_udev.sh usr/local/bin
haliburton/script/cpu_wdt usr/local/bin
haliburton/script/50-ttyUSB-C0.rules etc/udev/rules.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ depmod -a
sudo chmod +x /usr/local/bin/udev_prefix.sh
sudo chmod +x /usr/local/bin/popmsg.sh
sudo chmod +x /usr/local/bin/reload_udev.sh
sudo chmod +x /usr/local/bin/cpu_wdt

/usr/local/bin/platform_api_mgnt.sh install
/etc/init.d/fancontrol.sh install
/usr/local/bin/reload_udev.sh

systemctl enable platform-modules-haliburton.service
systemctl enable fancontrol.service
systemctl enable cpu_wdt.service

systemctl start platform-modules-haliburton.service
systemctl start fancontrol.service
systemctl start fancontrol.service
systemctl start cpu_wdt.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash

SYSLOG_IDENTIFIER="cpu_wdt"
CPUWDT_MAIN_TASK_RUNNING_FLAG=true
TIMEOUT=180
KEEPALIVE=60

function log_info()
{
logger -p info -t ${SYSLOG_IDENTIFIER} "$@"
}

function usage()
{
echo "Usage: $0 ACTION [OPTIONS]..."
echo ""
echo "Actions:"
echo " start Start CPU WDT"
echo " stop Stop CPU WDT"
echo ""
echo "Options:"
echo " -h Show this help"
echo " -t <timeout> WDT timeout period: {30|60|180}, default 180"
echo " -k <keepalive> WDT keep alive period, {1..(timeout-5)}, default 60"
exit 1
}

function validate_action()
{
if [[ "${ACTION}" != "start" && "${ACTION}" != "stop" ]]; then
echo -e "Invalid action: ${ACTION}\n"
usage
fi
}

function validate_options()
{
if [[ ${TIMEOUT} != "30" && ${TIMEOUT} != "60" && ${TIMEOUT} != "180" ]]; then
echo -e "Invalid timeout value: ${TIMEOUT}\n"
usage
fi
if [[ ${KEEPALIVE} -le 0 || ${KEEPALIVE} -gt $((TIMEOUT - 5)) ]]; then
echo "Invalid keepalive value: ${KEEPALIVE}"
echo ""
usage
fi
}

trap 'log_info "Caught SIGHUP - ignoring..."' SIGHUP
trap 'log_info "Caught SIGINT - exiting..."; CPUWDT_MAIN_TASK_RUNNING_FLAG=false' SIGINT
trap 'log_info "Caught SIGTERM - exiting..."; CPUWDT_MAIN_TASK_RUNNING_FLAG=false' SIGTERM

ACTION=$1
shift
validate_action

while getopts "t:k:" OPTION; do
case $OPTION in
t)
TIMEOUT=${OPTARG}
;;
k)
KEEPALIVE=${OPTARG}
;;
*)
usage
esac
done

validate_options

if [[ "${ACTION}" == "start" ]]; then
# enable
log_info "Enable CPU WDT.."
watchdogutil arm -s "${TIMEOUT}" > /dev/null
log_info "CPU WDT has been enabled with $TIMEOUT seconds timeout"

# keep alive
log_info "Enable keep alive messaging every $KEEPALIVE seconds"
while [[ ${CPUWDT_MAIN_TASK_RUNNING_FLAG} == "true" ]]; do
watchdogutil arm -s "${TIMEOUT}" > /dev/null
log_info "Keep alive message sent [RC=$?]. Will sleep ${KEEPALIVE} seconds."
sleep "${KEEPALIVE}"
done
log_info "Keep alive messaging has been disabled"
fi

log_info "Disable CPU WDT.."
watchdogutil disarm
log_info "CPU WDT has been disabled!"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=CPU WDT
After=platform-modules-haliburton.service
Requires=platform-modules-haliburton.service

[Service]
ExecStart=-/usr/local/bin/cpu_wdt start

[Install]
WantedBy=multi-user.target

0 comments on commit 0baa641

Please sign in to comment.