Skip to content

Commit

Permalink
Fix to improve hostname handling (#12064)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
devpatha authored and abdosi committed Jan 30, 2023
1 parent cd2bb08 commit 4dba276
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions files/image_config/hostname/hostname-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
CURRENT_HOSTNAME=`hostname`
HOSTNAME=`sonic-cfggen -d -v DEVICE_METADATA[\'localhost\'][\'hostname\']`

if [ -z "$HOSTNAME" ] ; then
echo "Missing hostname in the config file, setting to default 'sonic'"
HOSTNAME='sonic'
fi

echo $HOSTNAME > /etc/hostname
hostname -F /etc/hostname

Expand Down

0 comments on commit 4dba276

Please sign in to comment.