Skip to content

Commit 461470b

Browse files
Refactor fast-reboot script. Generate fast-reboot-dumps into configurable directory (#208)
1 parent b87ea44 commit 461470b

2 files changed

Lines changed: 20 additions & 25 deletions

File tree

scripts/fast-reboot

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/bin/bash
22

33
# Check root privileges
4-
if [ "$EUID" -ne 0 ]
4+
if [[ "$EUID" -ne 0 ]]
55
then
66
echo "Please run as root"
77
exit
88
fi
99

1010

1111
# Unload the previously loaded kernel if any loaded
12-
if [ "$(cat /sys/kernel/kexec_loaded)" -eq 1 ]
12+
if [[ "$(cat /sys/kernel/kexec_loaded)" -eq 1 ]]
1313
then
1414
/sbin/kexec -u
1515
fi
@@ -27,33 +27,28 @@ sonic_asic_type=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
2727
/sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS"
2828

2929
# Dump the ARP and FDB tables to files also as default routes for both IPv4 and IPv6
30-
/usr/bin/fast-reboot-dump.py
31-
docker cp /tmp/fdb.json swss:/
32-
docker cp /tmp/arp.json swss:/
33-
if [ -e /tmp/default_routes.json ]
34-
then
35-
docker cp /tmp/default_routes.json swss:/
36-
fi
30+
# into /host/fast-reboot
31+
mkdir -p /host/fast-reboot
32+
/usr/bin/fast-reboot-dump.py /host/fast-reboot
3733

38-
# Kill bgpd to enable graceful restart of BGP
39-
docker exec -ti bgp killall -9 watchquagga
34+
# Kill bgpd to start the bgp graceful restart procedure
4035
docker exec -ti bgp killall -9 zebra
4136
docker exec -ti bgp killall -9 bgpd
4237

4338
# Kill lldp, otherwise it sends informotion about reboot
44-
docker kill lldp
39+
docker kill lldp > /dev/null
4540

4641
# Kill teamd, otherwise it gets down all LAGs
47-
docker kill teamd
42+
docker kill teamd > /dev/null
4843

49-
# Kill other containers to make reboot faster
50-
docker ps -qa | xargs docker kill
44+
# Kill other containers to make the reboot faster
45+
docker ps -q | xargs docker kill > /dev/null
5146

5247
# Stop the docker container engine. Otherwise we will have a broken docker storage
5348
systemctl stop docker.service
5449

5550
# Stop opennsl modules for Broadcom platform
56-
if [ "$sonic_asic_type" = 'broadcom' ];
51+
if [[ "$sonic_asic_type" = 'broadcom' ]];
5752
then
5853
service_name=$(systemctl list-units --plain --no-pager --no-legend --type=service | grep opennsl | cut -f 1 -d' ')
5954
systemctl stop "$service_name"

scripts/fast-reboot-dump.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import socket
66
import struct
7+
import sys
78
import os
89
from fcntl import ioctl
910
import binascii
@@ -244,18 +245,17 @@ def generate_default_route_entries(filename):
244245

245246
db.close(db.APPL_DB)
246247

247-
if len(default_routes_output) > 0:
248-
with open(filename, 'w') as fp:
249-
json.dump(default_routes_output, fp, indent=2, separators=(',', ': '))
250-
else:
251-
if os.path.isfile(filename):
252-
os.unlink(filename)
248+
with open(filename, 'w') as fp:
249+
json.dump(default_routes_output, fp, indent=2, separators=(',', ': '))
253250

254251

255252
def main():
256-
all_available_macs, map_mac_ip_per_vlan = generate_fdb_entries('/tmp/fdb.json')
257-
arp_entries = generate_arp_entries('/tmp/arp.json', all_available_macs)
258-
generate_default_route_entries('/tmp/default_routes.json')
253+
root_dir = '/tmp'
254+
if len(sys.argv) > 1 and os.path.isdir(sys.argv[1]):
255+
root_dir = sys.argv[1]
256+
all_available_macs, map_mac_ip_per_vlan = generate_fdb_entries(root_dir + '/fdb.json')
257+
arp_entries = generate_arp_entries(root_dir + '/arp.json', all_available_macs)
258+
generate_default_route_entries(root_dir + '/default_routes.json')
259259
garp_send(arp_entries, map_mac_ip_per_vlan)
260260

261261
return

0 commit comments

Comments
 (0)