Skip to content

Commit

Permalink
remove negative exit codes and other shellchecks in wedge_power.sh (#228
Browse files Browse the repository at this point in the history
)

Summary:
Pull Request resolved: #228

I was getting shellcheck errors when editing this file in another diff. Negative exit codes and return values are not supported in bash: https://unix.stackexchange.com/questions/418784/what-is-the-min-and-max-values-of-exit-codes-in-linux

Test Plan: This is the only usage of it in code and it doesn't rely on a negative exit code (which couldn't happen anyways): https://www.internalfb.com/code/search?q=WEDGE_POWER_RESET_CMD

Reviewed By: doranand

Differential Revision: D47138227

fbshipit-source-id: ac27ea6ad24768d992c90f8546efd94ada319415
  • Loading branch information
Scott8440 authored and facebook-github-bot committed Aug 14, 2023
1 parent 0363781 commit 0554af8
Showing 1 changed file with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ prog="$0"
PWD1014A_SYSFS_DIR=$(i2c_device_sysfs_abspath 2-003a)
PWR_SYSTEM_SYSFS="${SYSCPLD_SYSFS_DIR}/pwr_cyc_all_n"
PWR_USRV_RST_SYSFS="${SYSCPLD_SYSFS_DIR}/usrv_rst_n"
PWR_TH_RST_SYSFS="${SYSCPLD_SYSFS_DIR}/th_sys_rst_n"
ALT_SYSRESET_SYSFS="${PWD1014A_SYSFS_DIR}/mod_hard_powercycle"

usage() {
Expand All @@ -50,7 +49,7 @@ usage() {
}

is_main_power_on() {
status=$(cat $PWR_MAIN_SYSFS | head -1 )
status=$(cat "$PWR_MAIN_SYSFS" | head -1 )
if [ "$status" == "0x1" ]; then
return 0 # powered on
else
Expand Down Expand Up @@ -82,12 +81,12 @@ do_status() {

do_on_com_e() {
logger -p user.crit "Powering on microserver..."
echo 1 > $PWR_USRV_SYSFS
echo 1 > "$PWR_USRV_SYSFS"
}

do_on_main_pwr() {
logger -p user.crit "Turning on main power..."
echo 1 > $PWR_MAIN_SYSFS
echo 1 > "$PWR_MAIN_SYSFS"
}

do_on() {
Expand All @@ -101,7 +100,7 @@ do_on() {
;;
*)
usage
exit -1
exit 1
;;

esac
Expand Down Expand Up @@ -130,12 +129,12 @@ do_on() {

do_off_com_e() {
logger -p user.crit "Powering off microserver..."
echo 0 > $PWR_USRV_SYSFS
echo 0 > "$PWR_USRV_SYSFS"
}

do_off_main_pwr() {
logger -p user.crit "Turning off main power..."
echo 0 > $PWR_MAIN_SYSFS
echo 0 > "$PWR_MAIN_SYSFS"
}

do_off() {
Expand All @@ -158,7 +157,7 @@ do_reset() {
;;
*)
usage
exit -1
exit 1
;;
esac
done
Expand All @@ -167,33 +166,33 @@ do_reset() {
logger -p user.crit "Power reset the whole system..."
echo -n "Power reset the whole system ..."
sleep 1
echo 0 > $PWR_SYSTEM_SYSFS
echo 0 > "$PWR_SYSTEM_SYSFS"
# Echo 0 above should work already. However, after CPLD upgrade,
# We need to re-generate the pulse to make this work
usleep $pulse_us
echo 1 > $PWR_SYSTEM_SYSFS
echo 1 > "$PWR_SYSTEM_SYSFS"
usleep $pulse_us
echo 0 > $PWR_SYSTEM_SYSFS
echo 0 > "$PWR_SYSTEM_SYSFS"
usleep $pulse_us
echo 1 > $PWR_SYSTEM_SYSFS
echo 1 > "$PWR_SYSTEM_SYSFS"
logger -p user.crit "Chassis power failed through CPLD. Will try pwr1014a in 5 sec..."
sleep 5
echo 0 > $ALT_SYSRESET_SYSFS
echo 0 > "$ALT_SYSRESET_SYSFS"
sleep 1
else
if ! wedge_is_us_on; then
echo "Power resetting microserver that is powered off has no effect."
echo "Use '$prog on' to power the microserver on"
return -1
return 1
fi
# reset TH first
reset_brcm.sh

logger -p user.crit "Power reset microserver..."
echo -n "Power reset microserver ..."
echo 0 > $PWR_USRV_RST_SYSFS
echo 0 > "$PWR_USRV_RST_SYSFS"
sleep 1
echo 1 > $PWR_USRV_RST_SYSFS
echo 1 > "$PWR_USRV_RST_SYSFS"
logger "Successfully power reset micro-server"
fi
echo " Done"
Expand All @@ -202,27 +201,27 @@ do_reset() {

if [ $# -lt 1 ]; then
usage
exit -1
exit 1
fi

command="$1"
shift

case "$command" in
status)
do_status $@
do_status "$@"
;;
on)
do_on $@
do_on "$@"
;;
off)
do_off $@
do_off "$@"
;;
reset)
do_reset $@
do_reset "$@"
;;
*)
usage
exit -1
exit 1
;;
esac

0 comments on commit 0554af8

Please sign in to comment.