charm-swift-storage/hooks/swift-storage-node-common

110 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
set -u
DEFAULT_ETH=$(ip route | grep default | awk '{ print $5 }')
IP=$(ifconfig $DEFAULT_ETH | grep 'inet addr' | awk '{ print $2 }' | cut -d: -f2)
# TODO: Need to use different addresses for internal swift traffic
# as this the only security measure in place is network isolation
STORAGE_LOCAL_NET_IP=$IP
PACKAGES="swift swift-account swift-container swift-object xfsprogs"
DEVICES=$(config-get block-device)
PPA=$(config-get swift-release)
if [ "$DEVICES" = "guess" ]; then
# This should be more smart
DEVICES=$(awk '($4 ~ /^(sd[a-z]|vd[a-z]|cciss\/c[0-9]d[0-9])$/) && ($4 != "sda") && ($4 != "vda") && ($4 != "cciss/c0d0") {print $4}' </proc/partitions)
fi
function set_swift_hash {
# TODO: Do this with augeas and put in a utility function for use elsewhere
cat >/etc/swift/swift.conf <<EOF
[swift-hash]
# random unique string that can never change (DO NOT LOSE)
swift_hash_path_suffix = $1
EOF
}
function configure_rsyncd {
cat >/etc/rsyncd.conf <<EOF
uid = swift
gid = swift
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
address = $STORAGE_LOCAL_NET_IP
[account]
max connections = 2
path = /srv/node/
read only = false
lock file = /var/lock/account.lock
[container]
max connections = 2
path = /srv/node/
read only = false
lock file = /var/lock/container.lock
[object]
max connections = 2
path = /srv/node/
read only = false
lock file = /var/lock/object.lock
EOF
perl -pi -e 's/RSYNC_ENABLE=false/RSYNC_ENABLE=true/' /etc/default/rsync
service rsync start
}
function create_server_conf {
# $1 should be: account, container or object
case $1 in
"account") subconf="replicator auditor reaper" ;;
"object"|"container") subconf="replicator updater auditor sync" ;;
esac
cat >/etc/swift/$1-server.conf <<EOF
[DEFAULT]
bind_ip = $STORAGE_LOCAL_NET_IP
workers = 2
[pipeline:main]
pipeline = $1-server
[app:$1-server]
use = egg:swift#$1
EOF
for i in $subconf ; do
echo -e "[$1-$i]\n" >>/etc/swift/$1-server.conf
done
}
function setup_storage {
# TODO: remove previous lines from fstab
mkdir -p /srv/node
for DEVICE in $DEVICES; do
SRVNODENAME="$(echo $DEVICE | sed 's/[\/:]/-/g')"
if grep $DEVICE </proc/mounts >/dev/null; then
umount $(cat /proc/mounts | grep $DEVICE | awk '{ print $2 }')
fi
mkfs.xfs -f -i size=1024 /dev/$DEVICE
echo "/dev/$DEVICE /srv/node/$SRVNODENAME xfs noatime,nodiratime,nobarrier,logbufs=8 0 0" >> /etc/fstab
mkdir -p /srv/node/$SRVNODENAME
mount /srv/node/$SRVNODENAME
done
chown -R swift:swift /srv/node
}
function add_ppa {
[[ $PPA == "distro" ]] && return 0
. /etc/lsb-release
[[ -z $PPA ]] && return 0
[[ $PPA == "milestone" ]] && PPA="release"
PPA_URL="deb http://ppa.launchpad.net/swift-core/$PPA/ubuntu $DISTRIB_CODENAME main"
add-apt-repository "$PPA_URL" || exit 1
}