_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 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}" } die(){ _exit_handler_reason="$1" echo "error: $1" >&2 exit 1 } trap _exit_handler EXIT set -e export HOME=/root cd "$HOME" cat >/usr/local/bin/run-gist </dev/null curl -sL "\${gist_download_url}" | tar -x -z --strip=1 chmod a+x ./run ./run popd >/dev/null rm -rf "\${extract_dir}" EOF chmod a+x /usr/local/bin/run-gist echo "ensuring internet connectivity..." curl -o /dev/null -I --silent --fail --show-error --retry 100 'http://bex-status.s3.amazonaws.com/status.json' echo "found an internet connection." echo "configuring hostname from aws metadata service" host_title="${AWS_STACK_NAME}-$(echo "${AWS_INSTANCE_LOGICAL_NAME}" | sed 's/LaunchConfiguration$//')" # -$(uuidgen | cut -d'-' -f 1)" private_hostname=$(curl http://169.254.169.254/latest/meta-data/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 < /etc/apt/sources.list.d/logentries.list echo "enabling mirroring for security apt sources" sed -i "s/security\.ubuntu\.com/${AWS_REGION}.ec2.archive.ubuntu.com/g" /etc/apt/sources.list echo "disablng kernel and initramfs updates" echo $(dpkg -l "*$(uname -r)*" | grep image | awk '{print $2}') hold | dpkg --set-selections sed -i 's/=yes/=no/g' /etc/initramfs-tools/update-initramfs.conf echo "installing packages" apt-get clean apt-get update apt-get upgrade -qy apt-get install -qy python-setuptools python-pip python-setproctitle htop tree btrfs-tools xz-utils logentries bundler ruby-nokogiri pip install -q awscli gem install -q --no-rdoc --no-ri aws-sdk echo "starting remote logging" if [ -n "$LOGENTRIES_ACCOUNT_KEY" ]; then le init --account-key="${LOGENTRIES_ACCOUNT_KEY}" --agent-key="$(uuidgen)" le register --force --name="${host_title}" --hostname="${private_hostname}" apt-get install -qy logentries-daemon logs_to_follow="syslog messages dmesg auth.log boot.log daemon.log dpkg.log kern.log cron secure faillog cloud-init-output.log" for log_name in ${logs_to_follow}; do log_path="/var/log/${log_name}" if [ -f "${log_path}" ]; then log_name=$(basename "${log_path}" '.log') le follow --name="${log_name}" "${log_path}" 2>/dev/null 1>&2 fi done service logentries restart fi echo "installing aws cfn-tools" easy_install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz cfn-init --region="${AWS_REGION}" --stack="${AWS_STACK_NAME}" --resource="${AWS_INSTANCE_LOGICAL_NAME}" || die 'Failed to run cfn-init'