From af43d0db1ecc658101431eb12a3a187befa7e947 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Wed, 8 Feb 2017 16:26:11 +0100 Subject: [PATCH] library/roles/smartgears/smartgears_egi_image/templates/smartgears-setup.sh.j2: More complete fix for the hostname handling. --- .../templates/smartgears-setup.sh.j2 | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/smartgears/smartgears_egi_image/templates/smartgears-setup.sh.j2 b/smartgears/smartgears_egi_image/templates/smartgears-setup.sh.j2 index 6505f22..b596964 100755 --- a/smartgears/smartgears_egi_image/templates/smartgears-setup.sh.j2 +++ b/smartgears/smartgears_egi_image/templates/smartgears-setup.sh.j2 @@ -18,6 +18,7 @@ FQDN_HOST= PUB_FQDN_HOST= PUBLIC_IP= MAIN_IP= +WORKING_REVERSE_RESOLUTION=0 RETVAL=0 CLOUD_INSTANCE_DIR=/var/lib/cloud/instance MEM=$( free -m | egrep ^Mem | awk '{ print $2 }' ) @@ -69,23 +70,28 @@ function find_public_ip() { RET_FQDN=$? if [ $RET_FQDN -eq 0 ] ; then PUB_FQDN_HOST=$( host $PUBLIC_IP | awk '{print $5}' | sed -e 's/\.$//g' ) + else + echo "No reverse resolution available. WPS will not work." >> $LOG_FILE + WORKING_REVERSE_RESOLUTION=1 fi } function modify_hosts_file() { echo "-- modify_hosts_file" >> $LOG_FILE # Set the hosts file with the new data. Set /etc/hostname too - grep -v $HOST $HOSTS_FILE > $HOSTS_FILE.tmp - if [ "${FQDN_HOST}" == "${HOST}" ] ; then - FQDN_HOST=${HOST}.localhost - fi - SHORT_HOSTNAME=$( echo ${PUB_FQDN_HOST} | cut -d . -f 1 - ) - echo "${PUBLIC_IP} ${FQDN_HOST} ${PUB_FQDN_HOST} ${SHORT_HOSTNAME} ${HOST}" >> $HOSTS_FILE.tmp - mv $HOSTS_FILE.tmp $HOSTS_FILE - chmod 644 $HOSTS_FILE - chown root:root $HOSTS_FILE - if [ ! -z ${SHORT_HOSTNAME} ] ; then - echo "${SHORT_HOSTNAME}" > /etc/hostname + if [ $WORKING_REVERSE_RESOLUTION -eq 0 ] ; then + grep -v $HOST $HOSTS_FILE > $HOSTS_FILE.tmp + if [ "${FQDN_HOST}" == "${HOST}" ] ; then + LOCAL_HOSTNAME=${HOST} + fi + SHORT_HOSTNAME=$( echo ${PUB_FQDN_HOST} | cut -d . -f 1 - ) + echo "${PUBLIC_IP} ${PUB_FQDN_HOST} ${SHORT_HOSTNAME} ${LOCAL_HOSTNAME}" >> $HOSTS_FILE.tmp + mv $HOSTS_FILE.tmp $HOSTS_FILE + chmod 644 $HOSTS_FILE + chown root:root $HOSTS_FILE + if [ ! -z ${SHORT_HOSTNAME} ] ; then + echo "${SHORT_HOSTNAME}" > /etc/hostname + fi fi }