forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreboot
More file actions
executable file
·43 lines (36 loc) · 1.16 KB
/
Copy pathreboot
File metadata and controls
executable file
·43 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
REBOOT_USER=$(logname)
REBOOT_TIME=$(date)
PLATFORM=$(sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)
DEVPATH="/usr/share/sonic/device"
PLAT_REBOOT="platform_reboot"
REBOOT_CAUSE_FILE="/var/cache/sonic/reboot-cause.txt"
function stop_sonic_services()
{
echo "Stopping syncd..."
docker exec -i syncd /usr/bin/syncd_request_shutdown --cold > /dev/null
sleep 3
}
# Exit if not superuser
if [[ "$EUID" -ne 0 ]]; then
echo "This command must be run as root" >&2
exit 1
fi
# Stop SONiC services gracefully.
stop_sonic_services
# 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}
sync
sleep 3
if [ -x ${DEVPATH}/${PLATFORM}/${PLAT_REBOOT} ]; then
echo "Rebooting with platform ${PLATFORM} specific tool ..."
exec ${DEVPATH}/${PLATFORM}/${PLAT_REBOOT} $@
else
# If no platform-specific reboot tool, just run /sbin/reboot
exec /sbin/reboot $@
fi
# Should never reach here
echo "Reboot failed!" >&2
exit 1