From 26c3709786a4072625d7f3ebb9f2e52d798a3ba0 Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Thu, 18 Jan 2018 15:53:15 -0800 Subject: [PATCH] [reboot] While rebooting device, execute platform specific reboot tool when available (#188) * [fast-reboot] Explicitly call Linux native reboot tool * [reboot tool] Reboot device with platform specific tool when available /usr/bin is in front of /sbin in search path. Adding reboot script here will get executed when reboot was called without absolute path. This script will call platform specific reboot tool (name: platform_reboot under device folder) when available. Otherwise, dispatch to native Linux reboot. * [reboot] call sync before calling platform specific reboot tool The platform specific reboot tool could be power cycling. * [reboot] sleep 3 seconds after sync-ing * [reboot] also stop snmp service --- scripts/fast-reboot | 4 ++-- scripts/reboot | 28 ++++++++++++++++++++++++++++ setup.py | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100755 scripts/reboot diff --git a/scripts/fast-reboot b/scripts/fast-reboot index 21d153e8f3..ba397e5ea0 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -59,6 +59,6 @@ sync sleep 1 sync -# Reboot +# Reboot: explicity call Linux native reboot under sbin echo "Rebooting to $NEXT_SONIC_IMAGE..." -reboot +/sbin/reboot diff --git a/scripts/reboot b/scripts/reboot new file mode 100755 index 0000000000..019e5ad762 --- /dev/null +++ b/scripts/reboot @@ -0,0 +1,28 @@ +#! /bin/bash + +function stop_sonic_services() +{ + echo "Stopping sonic services..." + systemctl stop swss + systemctl stop teamd + systemctl stop bgp + systemctl stop lldp + systemctl stop snmp +} + +# Obtain our platform as we will mount directories with these names in each docker +PLATFORM=`sonic-cfggen -v platform` + +DEVPATH="/usr/share/sonic/device" +REBOOT="platform_reboot" + +if [ -x ${DEVPATH}/${PLATFORM}/${REBOOT} ]; then + stop_sonic_services + sync + sleep 3 + echo "Rebooting with platform ${PLATFORM} specific tool ..." + ${DEVPATH}/${PLATFORM}/${REBOOT} + exit 0 +fi + +/sbin/reboot $@ diff --git a/setup.py b/setup.py index bec645946b..61e42fd438 100644 --- a/setup.py +++ b/setup.py @@ -49,6 +49,7 @@ def get_test_suite(): 'scripts/port2alias', 'scripts/portconfig', 'scripts/portstat', + 'scripts/reboot', 'scripts/teamshow' ], data_files=[