library/roles/smartgears/smartgears_egi_image/templates/smartgears-setup.sh.j2: More complete fix for the hostname handling.

This commit is contained in:
Andrea Dell'Amico 2017-02-08 16:26:11 +01:00
parent 9573124e3c
commit af43d0db1e
1 changed files with 17 additions and 11 deletions

View File

@ -18,6 +18,7 @@ FQDN_HOST=
PUB_FQDN_HOST= PUB_FQDN_HOST=
PUBLIC_IP= PUBLIC_IP=
MAIN_IP= MAIN_IP=
WORKING_REVERSE_RESOLUTION=0
RETVAL=0 RETVAL=0
CLOUD_INSTANCE_DIR=/var/lib/cloud/instance CLOUD_INSTANCE_DIR=/var/lib/cloud/instance
MEM=$( free -m | egrep ^Mem | awk '{ print $2 }' ) MEM=$( free -m | egrep ^Mem | awk '{ print $2 }' )
@ -69,23 +70,28 @@ function find_public_ip() {
RET_FQDN=$? RET_FQDN=$?
if [ $RET_FQDN -eq 0 ] ; then if [ $RET_FQDN -eq 0 ] ; then
PUB_FQDN_HOST=$( host $PUBLIC_IP | awk '{print $5}' | sed -e 's/\.$//g' ) 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 fi
} }
function modify_hosts_file() { function modify_hosts_file() {
echo "-- modify_hosts_file" >> $LOG_FILE echo "-- modify_hosts_file" >> $LOG_FILE
# Set the hosts file with the new data. Set /etc/hostname too # Set the hosts file with the new data. Set /etc/hostname too
grep -v $HOST $HOSTS_FILE > $HOSTS_FILE.tmp if [ $WORKING_REVERSE_RESOLUTION -eq 0 ] ; then
if [ "${FQDN_HOST}" == "${HOST}" ] ; then grep -v $HOST $HOSTS_FILE > $HOSTS_FILE.tmp
FQDN_HOST=${HOST}.localhost if [ "${FQDN_HOST}" == "${HOST}" ] ; then
fi LOCAL_HOSTNAME=${HOST}
SHORT_HOSTNAME=$( echo ${PUB_FQDN_HOST} | cut -d . -f 1 - ) fi
echo "${PUBLIC_IP} ${FQDN_HOST} ${PUB_FQDN_HOST} ${SHORT_HOSTNAME} ${HOST}" >> $HOSTS_FILE.tmp SHORT_HOSTNAME=$( echo ${PUB_FQDN_HOST} | cut -d . -f 1 - )
mv $HOSTS_FILE.tmp $HOSTS_FILE echo "${PUBLIC_IP} ${PUB_FQDN_HOST} ${SHORT_HOSTNAME} ${LOCAL_HOSTNAME}" >> $HOSTS_FILE.tmp
chmod 644 $HOSTS_FILE mv $HOSTS_FILE.tmp $HOSTS_FILE
chown root:root $HOSTS_FILE chmod 644 $HOSTS_FILE
if [ ! -z ${SHORT_HOSTNAME} ] ; then chown root:root $HOSTS_FILE
echo "${SHORT_HOSTNAME}" > /etc/hostname if [ ! -z ${SHORT_HOSTNAME} ] ; then
echo "${SHORT_HOSTNAME}" > /etc/hostname
fi
fi fi
} }