#!/bin/bash
# AWS Worker Bootstrap File # File used to configure worker nodes on AWS
# Change Host File Entries ENTRY=“SERVER_IP SERVER_HOSTNAME” FILE=/etc/hosts if grep -q “$ENTRY” $FILE; then
echo "entry already exists"
else
sh -c "echo $ENTRY >> $FILE"
fi
WORKER_PUBLIC_KEY=“WORKER_PUBLIC_KEY_TEMPLATE”
# add the public key to authorized keys USER=ubuntu
mkdir -p /home/$USER/.ssh && chmod 700 /home/$USER/.ssh
# Only access from the server node ENTRY=“from="SERVER_HOSTNAME" $WORKER_PUBLIC_KEY” FILE=/home/$USER/.ssh/authorized_keys if grep -q “$ENTRY” $FILE; then
echo "Key already exists in file"
else
echo $ENTRY >> $FILE
fi chmod 644 /home/$USER/.ssh/authorized_keys
# ec2 instance information curl -o /usr/local/bin/ec2-metadata s3.amazonaws.com/ec2metadata/ec2-metadata chmod 775 /usr/local/bin/ec2-metadata mkdir -p /etc/openstudio-server ec2-metadata -a -i -t -h -o -z -p -v > /etc/openstudio-server/instance.yml
# make sure the the /mnt directory exists if i2 instances. # For now this assumes that the volume is xvdb. In the future this # should be dynamic if ec2-metadata –instance-type | grep -q 'i2.'; then
mkfs.ext4 /dev/xvdb mkdir -p /mnt mount -t ext4 /dev/xvdb /mnt echo "/dev/xvdb /mnt auto noatime 0 0" | sudo tee -a /etc/fstab mount -a
fi
## Worker Data Configuration – On Vagrant this is a separate file
rm -f /tmp/snow.log
# Force the generation of various directories that are in the EBS mount rm -rf /mnt/openstudio mkdir -p /mnt/openstudio chown -R ubuntu:www-data /mnt/openstudio chmod -R 775 /mnt/openstudio
# save application files into the right directory rsync -a –chown ubuntu:www-data –exclude Gemfile.lock /data/worker-nodes/ /mnt/openstudio/
# install workflow dependencies # note: vagrant/ubuntu are now members of rbenv but it still doesn't work to not call sudo on bundle # Give full path to bundle because sudoers path is not available with cloud-init root cd /mnt/openstudio && /opt/rbenv/shims/bundle
# copy over the models needed for mongo cd /mnt/openstudio/rails-models && unzip -o rails-models.zip -d models
# rerun the permissions after unzipping the files chown -R ubuntu:www-data /mnt/openstudio find /mnt/openstudio -type d -print0 | xargs -0 chmod 775 find /mnt/openstudio -type f -print0 | xargs -0 chmod 664
## End Worker Data Configuration
# make sure supervisor is running sudo service supervisor start
# Rserve is now on the worker nodes for use by measures supervisorctl restart Rserve
file flag the user_data has completed cat /dev/null > /home/ubuntu/user_data_done