Skip to content

Instantly share code, notes, and snippets.

@lusis
Created March 24, 2012 05:04
Show Gist options
  • Save lusis/2178446 to your computer and use it in GitHub Desktop.
Save lusis/2178446 to your computer and use it in GitHub Desktop.
fairly unsafe cloudstack upstart script to set hostname
# cloudstack - Changes hostname
#
# changes hostname to match cloudstack instance name
# centos version (tested on CentOS 6)
description "Changes hostname"
start on started network
task
script
CS_GW=`/sbin/ip route | grep default | awk '{print $3}'`
CS_NAME=`/usr/bin/curl http://${CS_GW}/latest/local-hostname`
CUR_NAME=`grep HOSTNAME /etc/sysconfig/network | awk -F= '{print $2}'`
if [ ${CUR_NAME} != ${CS_NAME} ]; then
/bin/sed -ie "s/$CUR_NAME/$CS_NAME/g" /etc/sysconfig/network
/bin/hostname $CS_NAME
fi
end script
# cloudstack - Changes hostname
#
# changes hostname to match cloudstack instance name
# ubuntu version (tested on oneiric)
description "Changes hostname"
start on net-device-up
task
script
CS_GW=`/sbin/ip route | grep default | awk '{print $3}'`
CS_NAME=`/usr/bin/curl http://${CS_GW}/latest/local-hostname`
CUR_NAME=`cat /etc/hostname`
if [ ${CUR_NAME} != ${CS_NAME} ]; then
/bin/sed -ie "s/$CUR_NAME/$CS_NAME/g" /etc/hosts
/bin/sed -ie "s/$CUR_NAME/$CS_NAME/g" /etc/hostname
/bin/hostname -b -F /etc/hostname
fi
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment