-
Notifications
You must be signed in to change notification settings - Fork 670
/
Copy pathfast-reboot
executable file
·126 lines (104 loc) · 4.12 KB
/
fast-reboot
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
REBOOT_USER=$(logname)
REBOOT_TIME=$(date)
REBOOT_CAUSE_FILE="/var/cache/sonic/reboot-cause.txt"
# Check root privileges
if [[ "$EUID" -ne 0 ]]
then
echo "This command must be run as root" >&2
exit
fi
# Unload the previously loaded kernel if any loaded
if [[ "$(cat /sys/kernel/kexec_loaded)" -eq 1 ]]
then
/sbin/kexec -u
fi
# Kernel and initrd image
NEXT_SONIC_IMAGE=$(sonic_installer list | grep "Next: " | cut -d ' ' -f 2)
if grep -q aboot_platform= /host/machine.conf; then
IMAGE_PATH="/host/image-${NEXT_SONIC_IMAGE#SONiC-OS-}"
KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)"
BOOT_OPTIONS="$(cat "$IMAGE_PATH/kernel-cmdline" | tr '\n' ' ') fast-reboot"
elif grep -q onie_platform= /host/machine.conf; then
KERNEL_OPTIONS=$(cat /host/grub/grub.cfg | sed "/$NEXT_SONIC_IMAGE'/,/}/"'!'"g" | grep linux)
KERNEL_IMAGE="/host$(echo $KERNEL_OPTIONS | cut -d ' ' -f 2)"
BOOT_OPTIONS="$(echo $KERNEL_OPTIONS | sed -e 's/\s*linux\s*/BOOT_IMAGE=/') fast-reboot"
else
echo "Unknown bootloader. fast-reboot is not supported."
exit 1
fi
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
sonic_asic_type=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
# Install new FW for mellanox platforms before control plane goes down
# So on boot switch will not spend time to upgrade FW increasing the CP downtime
if [[ "$sonic_asic_type" == "mellanox" ]];
then
CURRENT_SONIC_IMAGE=$(sonic_installer list | grep "Current: " | cut -d ' ' -f 2)
if [[ "${CURRENT_SONIC_IMAGE}" != "${NEXT_SONIC_IMAGE}" ]]; then
echo "Prepare ASIC to fast reboot: install new FW if requiered"
NEXT_IMAGE_FS_PATH="/host/image-${NEXT_SONIC_IMAGE#SONiC-OS-}/fs.squashfs"
FS_MOUNTPOINT="/tmp/image-${NEXT_SONIC_IMAGE#SONiC-OS-}-fs"
mkdir -p "$FS_MOUNTPOINT"
mount -t squashfs "$NEXT_IMAGE_FS_PATH" "$FS_MOUNTPOINT"
/usr/bin/mlnx-fw-upgrade.sh "$FS_MOUNTPOINT/etc/mlnx/fw-SPC.mfa"
EXIT_CODE=$?
umount "$FS_MOUNTPOINT"
if [[ $EXIT_CODE != 0 ]]; then
echo "Failed to burn FW"
exit 1
fi
fi
fi
# Load kernel into the memory
/sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS"
# Dump the ARP and FDB tables to files also as default routes for both IPv4 and IPv6
# into /host/fast-reboot
mkdir -p /host/fast-reboot
/usr/bin/fast-reboot-dump.py -t /host/fast-reboot
# Kill bgpd to start the bgp graceful restart procedure
docker exec -i bgp killall -9 zebra
docker exec -i bgp killall -9 bgpd
# Kill lldp, otherwise it sends informotion about reboot
docker kill lldp > /dev/null
# Kill teamd, otherwise it gets down all LAGs
docker kill teamd > /dev/null
# syncd graceful stop is supported only for Broadcom platforms only for now
if [[ "$sonic_asic_type" = 'broadcom' ]];
then
# Gracefully stop syncd
docker exec -i syncd /usr/bin/syncd_request_shutdown --cold > /dev/null
# Check that syncd was stopped
while docker top syncd | grep -q /usr/bin/syncd
do
sleep 0.1
done
fi
# Kill other containers to make the reboot faster
docker ps -q | xargs docker kill > /dev/null
# Stop the docker container engine. Otherwise we will have a broken docker storage
systemctl stop docker.service
# Stop opennsl modules for Broadcom platform
if [[ "$sonic_asic_type" = 'broadcom' ]];
then
service_name=$(systemctl list-units --plain --no-pager --no-legend --type=service | grep opennsl | cut -f 1 -d' ')
systemctl stop "$service_name"
fi
# Stop kernel modules for Nephos platform
if [[ "$sonic_asic_type" = 'nephos' ]];
then
systemctl stop nps-modules-`uname -r`.service
fi
# Update the reboot cause file to reflect that user issued 'fast-reboot' command
# Upon next boot, the contents of this file will be used to determine the
# cause of the previous reboot
echo "User issued 'fast-reboot' command [User: ${REBOOT_USER}, Time: ${REBOOT_TIME}]" > ${REBOOT_CAUSE_FILE}
# Wait until all buffers synced with disk
sync
sleep 1
sync
# Reboot: explicity call Linux native reboot under sbin
echo "Rebooting to $NEXT_SONIC_IMAGE..."
exec /sbin/reboot
# Should never reach here
echo "fast-reboot failed!" >&2
exit 1