#!/bin/bash -lexv exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 echo <%= ref("AWS::StackName") %> > /tmp/stack_name # Helper function function error_exit { /usr/local/bin/cfn-signal -e 1 -r "$1" '<%= ref("WaitHandle") %>' exit 1 } # Wait for the EBS volume to show up while [ ! -e /dev/xvdf ]; do echo Waiting for EBS volume to attach; sleep 1; done /bin/mkdir /media/redis /sbin/mkfs -t ext4 /dev/xvdf echo "/dev/xvdf /media/redis auto defaults 0 0" >> /etc/fstab /bin/mount /media/redis /usr/bin/redis-cli shutdown sleep 10 mv /var/lib/redis/* /media/redis/ rm -r /var/lib/redis ln -s /media/redis /var/lib/redis chown -R redis:redis /var/lib/redis chown -R redis:redis /media/redis /usr/bin/redis-server # If all is well so signal success /usr/local/bin/cfn-signal -e $? -r "Ready to rock" '<%= ref("WaitHandle") %>' cat /proc/uptime | cut -f1 -d'.' > /tmp/time-to-boot