charm-swift-storage/hooks/swift-storage-node-relations

104 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
# test
set -eu
HOOKS_DIR="$CHARM_DIR/hooks"
ARG0=${0##*/}
if [[ -e $HOOKS_DIR/swift-storage-node-common ]] ; then
. $HOOKS_DIR/swift-storage-node-common
else
echo "ERROR: Could not load swift-storage-node-common from $HOOKS_DIR"
fi
function config_changed {
# perform openstack upgrade if openstack-origin has been bumped.
local install_src=$(config-get openstack-origin)
local cur=$(get_os_codename_package "python-swift")
local available=$(get_os_codename_install_source "$install_src")
if [[ "$available" != "unknown" ]] ; then
if dpkg --compare-versions $(get_os_version_codename "$cur") lt \
$(get_os_version_codename "$available") ; then
juju-log "$CHARM: Upgrading OpenStack release: $cur -> $available."
do_openstack_upgrade "$install_src" $PACKAGES
fi
fi
declare -a env_vars=()
for i in account container object ; do
port=$(config-get ${i}-server-port)
local url="http://$STORAGE_LOCAL_NET_IP:$port/recon/diskusage"
# append to env_vars
env_vars+=("OPENSTACK_PORT_${i^^}=$port")
env_vars+=("OPENSTACK_SWIFT_SERVICE_${i^^}=${i}-server")
# Ensure we have at least one device mounted as reported by swift-recon
env_vars+=('OPENSTACK_URL_'${i^^}'="'$url'|\"mounted\":+true"')
create_server_conf $i "$port"
done
# Save our scriptrc env variables for health checks
save_script_rc ${env_vars[@]}
}
function install_hook {
apt-get -y --force-yes install python-software-properties || exit 1
configure_install_source "$OPENSTACK_ORIGIN"
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y \
install --no-install-recommends $PACKAGES || exit 1
[[ ! -d /etc/swift ]] && mkdir /etc/swift
[[ ! -d /var/cache/swift ]] && mkdir /var/cache/swift
chown swift:swift /etc/swift
chown -R swift:swift /var/cache/swift
configure_rsyncd
swift-init all stop || true
setup_storage
config_changed
}
function storage_joined {
local devs=$(determine_block_devs)
local reldevices=""
for dev in $devs ; do
local srvnodename=$(basename $dev)
if [[ -n "$reldevices" ]] ; then
reldevices="$reldevices:$srvnodename"
else
reldevices="$srvnodename"
fi
done
relation-set zone="$(config-get zone)" \
device="$reldevices" \
object_port="$(config-get object-server-port)" \
container_port="$(config-get container-server-port)" \
account_port="$(config-get account-server-port)"
}
function storage_changed {
local rings_url=`relation-get rings_url`
local swift_hash=`relation-get swift_hash`
[[ -z $rings_url ]] || [[ -z $swift_hash ]] && exit 0
set_swift_hash $swift_hash
for i in account object container ; do
echo "Fetching $rings_url/$i.ring.gz"
wget "$rings_url/$i.ring.gz" -O /etc/swift/$i.ring.gz
done
set_swift_hash $swift_hash
chown swift -R /etc/swift
swift-init all start || true
}
case $ARG0 in
"install") install_hook ;;
"start"|"stop") exit 0 ;;
"config-changed") config_changed ;;
"swift-storage-relation-joined") storage_joined ;;
"swift-storage-relation-changed") storage_changed ;;
"config-changed") config_changed ;;
esac