Code to set up rethinkdb storage when USING_EBS

This commit is contained in:
troymc 2016-07-19 16:01:28 +02:00
parent 9f4c0dc835
commit 5843f8bbcb

View File

@ -65,30 +65,58 @@ def install_base_software():
software-properties-common python-software-properties \ software-properties-common python-software-properties \
python3-setuptools ipython3 sysstat s3cmd') python3-setuptools ipython3 sysstat s3cmd')
sudo('easy_install3 pip') sudo('easy_install3 pip')
sudo('pip3 install --upgrade pip wheel setuptools') # It seems that breaking apart
# sudo('pip3 install --upgrade pip wheel setuptools')
# into three separate statements is more reliable:
sudo('pip3 install --upgrade pip')
sudo('pip3 install --upgrade wheel')
sudo('pip3 install --upgrade setuptools')
# Prepare RethinkDB storage # Prepare RethinkDB storage
@task @task
@parallel @parallel
def prep_rethinkdb_storage(): def prep_rethinkdb_storage(USING_EBS):
"""Prepare RethinkDB storage""" """Prepare RethinkDB storage"""
with settings(warn_only=True): # Convert USING_EBS from a string to a bool
# preparing filesystem USING_EBS = (USING_EBS.lower() == 'true')
sudo("mkdir -p /data")
# Locally mounted storage (m3.2xlarge, but also c3.xxx) # Make the /data directory for RethinkDB data
sudo("mkdir -p /data")
# OLD: with settings(warn_only=True):
if USING_EBS: # on /dev/xvdp
# See https://tinyurl.com/h2nut68
sudo("mkfs -t ext4 /dev/xvdp")
sudo("mount /dev/xvdp /data")
# To mount this EBS volume on every system reboot,
# add an entry for the device to the /etc/fstab file.
# First, make a copy of the current /etc/fstab file
sudo("cp /etc/fstab /etc/fstab.orig")
# Append a line to /etc/fstab
sudo("echo '/dev/xvdp /data ext4 defaults,nofail,nobootwait 0 2' >> /etc/fstab")
# Veryify the /etc/fstab file. If something is wrong with it,
# then this should produce an error:
sudo("mount -a")
# Set the I/O scheduler for /dev/xdvp to deadline
with settings(sudo_user='root'):
sudo("echo deadline > /sys/block/xvdp/queue/scheduler")
else: # not using EBS.
# Using the "instance store" that comes with the instance.
# If the instance store comes with more than one volume,
# this only mounts ONE of them: /dev/xvdb
# For example, m3.2xlarge instances have /dev/xvdb and /dev/xvdc
# and /mnt is mounted on /dev/xvdb by default.
try: try:
sudo("umount /mnt") sudo("umount /mnt")
sudo("mkfs -t ext4 /dev/xvdb") sudo("mkfs -t ext4 /dev/xvdb")
sudo("mount /dev/xvdb /data") sudo("mount /dev/xvdb /data")
except: except:
pass pass
# persist settings to fstab
sudo("rm -rf /etc/fstab") sudo("rm -rf /etc/fstab")
sudo("echo 'LABEL=cloudimg-rootfs / ext4 defaults,discard 0 0' >> /etc/fstab") sudo("echo 'LABEL=cloudimg-rootfs / ext4 defaults,discard 0 0' >> /etc/fstab")
sudo("echo '/dev/xvdb /data ext4 defaults,noatime 0 0' >> /etc/fstab") sudo("echo '/dev/xvdb /data ext4 defaults,noatime 0 0' >> /etc/fstab")
# activate deadline scheduler (I/O scheduler) # Set the I/O scheduler for /dev/xdvb to deadline
with settings(sudo_user='root'): with settings(sudo_user='root'):
sudo("echo deadline > /sys/block/xvdb/queue/scheduler") sudo("echo deadline > /sys/block/xvdb/queue/scheduler")