Skip to content

Commit fa609b8

Browse files
devpathayxieca
authored andcommitted
Fix to improve hostname handling (sonic-net#12064)
* Fix to improve hostname handling If config_db.json is missing hostname entry, hostname-config.sh ends up deleting existing entry too and hostname changes to default 'localhost' * default hostname to 'sonic` if missing in config file
1 parent e973781 commit fa609b8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

files/image_config/hostname/hostname-config.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
CURRENT_HOSTNAME=`hostname`
44
HOSTNAME=`sonic-cfggen -d -v DEVICE_METADATA[\'localhost\'][\'hostname\']`
55

6+
if [ -z "$HOSTNAME" ] ; then
7+
echo "Missing hostname in the config file, setting to default 'sonic'"
8+
HOSTNAME='sonic'
9+
fi
10+
611
echo $HOSTNAME > /etc/hostname
712
hostname -F /etc/hostname
813

0 commit comments

Comments
 (0)