#!/usr/bin/env bash # Creates, formats and mounts swift storage loop drives # should be idempotent, probably isn't -- caveat emptor printf 'This script creates and mounts some loop back devices for swift, you good? [y/N] ' read ans if [ ! "$ans" = 'y' ] && [ ! "$ans" = 'Y' ]; then printf "Answer: '${ans}' was not 'Y' or 'y', exiting...\n" exit fi config='/etc/swift' storage='/srv/swift-storage' images="${storage}/images" mkdir -p "${images}" # https://wikitech.wikimedia.org/wiki/Swift/Setup_New_Swift_Cluster#Setup_file_systems image="${images}/swift-sdb.img" mount_point="${storage}/sdb1" label="swift-sdb1" mkdir -p "${mount_point}" if [ ! -f "${image}" ]; then touch "${image}" # resize img file to 5G truncate -s 10G "${image}" # format /sbin/mkfs.xfs -f -i size=512 -L "${label}" "${image}" if ! egrep -q "${mount_point}" /proc/mounts; then mount -t xfs -o loop,rw,noatime,nodiratime,nobarrier,logbufs=8 "${image}" "${mount_point}" chown -R swift:swift "${mount_point}" else printf '[$(tput red)ERROR$(tput sgr0)] Mount point %s already exists' "${mount_point}" exit 1 fi else printf '[$(tput red)ERROR$(tput sgr0)] File %s already exists' "${image}" exit 1 fi