_exit_handler_reason="" _exit_handler(){ exit_code="$?" if [ "${exit_code}" -eq 0 ]; then echo "Stacco cloud-init handler finished" cfn-signal -s true "${AWS_INSTANCE_WAIT_HANDLE}" else sleep 1000 echo "Stacco cloud-init handler aborted (${exit_code}: ${_exit_handler_reason})" cfn-signal -e "${exit_code}" -r "${_exit_handler_reason}" "${AWS_INSTANCE_WAIT_HANDLE}" fi exit "${exit_code}" } trap _exit_handler EXIT set -e export HOME=/root cd "$HOME" echo "configuring hostname from aws metadata service" host_title="${AWS_STACK_NAME}-$(echo "${AWS_INSTANCE_LOGICAL_NAME}" | sed 's/LaunchConfiguration$//')" private_hostname=$(curl -sL http://169.254.169.254/latest/meta-data/local-hostname) short_private_hostname=$(echo "${private_hostname}" | cut -d'.' -f 1) echo "${host_title}" > /etc/hostname hostname -b -F /etc/hostname sed -i '/127\.0\./d' /etc/hosts cat >>/etc/hosts <