diff --git a/files/image_config/hostname/hostname-config.sh b/files/image_config/hostname/hostname-config.sh index c2a4f1e546ce..5f4bfede2097 100755 --- a/files/image_config/hostname/hostname-config.sh +++ b/files/image_config/hostname/hostname-config.sh @@ -11,10 +11,16 @@ fi echo $HOSTNAME > /etc/hostname hostname -F /etc/hostname +#Don't update the /etc/hosts if hostname is not changed +#This is to prevent intermittent redis_chassis.server reachability issue +if [ $CURRENT_HOSTNAME == $HOSTNAME ] ; then + exit 0 +fi + # Remove the old hostname entry from hosts file. # But, 'localhost' entry is used by multiple applications. Don't remove it altogether. # Edit contents of /etc/hosts and put in /etc/hosts.new -if [ $CURRENT_HOSTNAME != "localhost" ] || [ $CURRENT_HOSTNAME == $HOSTNAME ] ; then +if [ $CURRENT_HOSTNAME != "localhost" ] ; then sed "/\s$CURRENT_HOSTNAME$/d" /etc/hosts > /etc/hosts.new else cp -f /etc/hosts /etc/hosts.new diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index dac74d19d4e4..f39d338656d7 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -132,12 +132,23 @@ function clean_up_chassis_db_tables() return fi - if [[ !($($SONIC_DB_CLI CHASSIS_APP_DB PING | grep -c True) -gt 0) ]]; then - return - fi + until [[ $($SONIC_DB_CLI CHASSIS_APP_DB PING | grep -c True) -gt 0 ]]; do + sleep 1 + done lc=`$SONIC_DB_CLI CONFIG_DB hget 'DEVICE_METADATA|localhost' 'hostname'` + until [[ -n "${lc}" ]]; do + lc=`$SONIC_DB_CLI CONFIG_DB hget 'DEVICE_METADATA|localhost' 'hostname'` + sleep 1 + done + debug "Chassis db clean up for ${SERVICE}$DEV. hostname=$lc" + asic=`$SONIC_DB_CLI CONFIG_DB hget 'DEVICE_METADATA|localhost' 'asic_name'` + until [[ -n "${asic}" ]]; do + asic=`$SONIC_DB_CLI CONFIG_DB hget 'DEVICE_METADATA|localhost' 'asic_name'` + sleep 1 + done + debug "Chassis db clean up for ${SERVICE}$DEV. asic=$asic" # First, delete SYSTEM_NEIGH entries num_neigh=`$SONIC_DB_CLI CHASSIS_APP_DB EVAL "