Skip to content

Commit d45fe19

Browse files
devpathaqiluo-msft
authored andcommitted
Fix to improve hostname handling (#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 2532be4 commit d45fe19

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

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)