Created
March 24, 2012 05:04
-
-
Save lusis/2178446 to your computer and use it in GitHub Desktop.
fairly unsafe cloudstack upstart script to set hostname
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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