Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reboot mechanism enhanced with reboot cause #3154

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions scripts/reboot
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ PLATFORM_FWUTIL_AU_REBOOT_HANDLE="platform_fw_au_reboot_handle"
REBOOT_SCRIPT_NAME=$(basename $0)
REBOOT_TYPE="${REBOOT_SCRIPT_NAME}"
TAG_LATEST=no
REBOOT_CAUSE=""

shyam77git marked this conversation as resolved.
Show resolved Hide resolved
function debug()
{
Expand Down Expand Up @@ -121,8 +122,8 @@ function show_help_and_exit()
echo " "
echo " Available options:"
echo " -h, -? : getting this help"
echo " -f : execute reboot force"

echo " -f : execute reboot force"
echo " -r : specify reboot cause (reason) string in quotes"
exit 0
}

Expand Down Expand Up @@ -172,22 +173,33 @@ function check_conflict_boot_in_fw_update()

function parse_options()
{
while getopts "h?vf" opt; do
while getopts "h?vftr:" opt; do
case ${opt} in
h|\? )
show_help_and_exit
;;
f )
REBOOT_FORCE=true
echo "force: $REBOOT_FORCE"
;;
v )
VERBOSE=yes
echo "verbose: $VERBOSE"
;;
t )
TAG_LATEST=no
echo "tag_latest: $TAG_LATEST"
;;
r )
REBOOT_CAUSE="$OPTARG"
# alternatives: $OPTARG or ${OPTARG} or "${OPTARG[@]}"
echo "reboot_cause: $REBOOT_CAUSE"
;;
esac
done
}

parse_options $@
parse_options "$@"

shyam77git marked this conversation as resolved.
Show resolved Hide resolved
# Exit if not superuser
if [[ "$EUID" -ne 0 ]]; then
Expand Down Expand Up @@ -215,10 +227,17 @@ fi

clear_warm_boot

# Update the reboot cause file to reflect that user issued 'reboot' command
# Upon next boot, the contents of this file will be used to determine the
# cause of the previous reboot
echo "User issued 'reboot' command [User: ${REBOOT_USER}, Time: ${REBOOT_TIME}]" > ${REBOOT_CAUSE_FILE}
# Update the 'reboot cause' file to reflect the right reboot reason.
# If 'reboot cause' is specified via the -r option, then update the same to
# this file; else update the 'reboot cause' to reflect that user issued the
# 'reboot' command.
# Upon next boot, the contents of this file will be used to determine
# the cause of the previous reboot.
if [[ -n $REBOOT_CAUSE ]]; then
echo "System triggered reboot. reason: '${REBOOT_CAUSE}' [User: system, Time: ${REBOOT_TIME}]" > ${REBOOT_CAUSE_FILE}
else
echo "User issued 'reboot' command [User: ${REBOOT_USER}, Time: ${REBOOT_TIME}]" > ${REBOOT_CAUSE_FILE}
fi
sync
/sbin/fstrim -av
sleep 3
Expand Down Expand Up @@ -260,4 +279,12 @@ if [ -x ${DEVPATH}/${PLATFORM}/${PLAT_REBOOT} ]; then
fi

VERBOSE=yes debug "Issuing OS-level reboot ..." >&2
exec /sbin/reboot $@
if [ $# -eq 2 ] && [ -n "$REBOOT_CAUSE" ]; then
echo "reboot cause specified"
exec /sbin/reboot
elif [ $# -gt 2 ] && [[ $REBOOT_FORCE == true ]] && [[ -n $REBOOT_CAUSE ]]; then
echo "both options - force reboot and reboot cause - specified"
exec /sbin/reboot -f
else
exec /sbin/reboot $@
fi
shyam77git marked this conversation as resolved.
Show resolved Hide resolved
Loading