./priv/roles/Common.sh in stacco-0.1.20 vs ./priv/roles/Common.sh in stacco-0.1.21

- old
+ new

@@ -1,10 +1,9 @@ _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})" @@ -20,27 +19,47 @@ exit 1 } trap _exit_handler EXIT set -e - -echo "running as $(whoami) in ${PWD}" export HOME=/root cd "$HOME" -echo "ensuring internet connectivity..." -while true; do - nat_status=$(curl -s -o /dev/null -I -w "%{http_code}" -m 2 http://bex-status.s3.amazonaws.com/status.json) - if [ "${nat_status}" = "200" ]; then - break - fi - sleep 2 -done +cat >/usr/local/bin/run-gist <<EOF + gist_id="\$1"; shift + gist_download_url="https://gist.github.com/\${gist_id}/download" + extract_dir=\$(mktemp -d /tmp/stacco.XXXXXXXX) + + echo "unpacking '\${gist_download_url}'..." + + pushd "\${extract_dir}" >/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 -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" +private_hostname=$(curl http://169.254.169.254/latest/meta-data/hostname) +echo "${private_hostname}" > /etc/hostname +hostname -b -F /etc/hostname +short_hostname=$(hostname -s) +sed -i '/127\.0\.0\.1/d' /etc/hosts +cat >>/etc/hosts <<EOF +127.0.0.1 localhost ${short_hostname} ${private_hostname} +EOF + 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" @@ -50,25 +69,15 @@ 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' -echo "configuring hostname from aws metadata service" -private_hostname=$(curl http://169.254.169.254/latest/meta-data/hostname) -echo "${private_hostname}" > /etc/hostname +for dev in /dev/xvd* /dev/ephemeral*; do + if [ -n "$(mount | awk '{print $1;}' | grep "^${dev}$")" ]; then + next + fi -hostname -b -F /etc/hostname -short_hostname=$(hostname -s) - -sed -i '/127\.0\.0\.1/d' /etc/hosts -cat >>/etc/hosts <<EOF -127.0.0.1 localhost ${short_hostname} ${private_hostname} -EOF - -if [ -b "/dev/xvdd" ]; then - echo "formatting and mounting /volumes storage" - mkfs.btrfs -L datavols /dev/xvdd - mkdir -p /volumes - mount /dev/xvdd /volumes - btrfs filesystem resize max /volumes + mkfs.btrfs "${dev}" 2>/dev/null || : + mount "${dev}" /mnt + btrfs filesystem resize max /mnt 2>/dev/null || : + umount /mnt fi -