6. tag_set = get_tag_set(@ec2, @instanceID)
tag_set.each do |tag|
p tag[:key]
if /name/i =~ tag[:key]
@name = tag[:value]
if @name.length > 0
`sed -i -e "/^127.0.0.1/d" /etc/hosts`
`echo "127.0.0.1 localhost localhost.localdomain #{@name}" >> /etc/hosts`
`sed -i -e "/^HOSTNAME/d" /etc/sysconfig/network`
`echo "HOSTNAME=#{@name}" >> /etc/sysconfig/network`
`hostname #{@name}`
end
end
end
7. 作成したスクリプトを実行します。
# ruby setHostName.rb
# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain LogicApp01
起動時に作成したスクリプトが毎回実行されるように、/etc/rc.d/rc.localに記載
します。
# vi /etc/rc.d/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/usr/bin/ruby /opt/aws/setHostName.rb