~niedbalski/charms/precise/swift-storage/add-fstab-persist

« back to all changes in this revision

Viewing changes to hooks/swift-storage-node-relations

  • Committer: Adam Gandelman
  • Date: 2013-01-07 23:25:53 UTC
  • mfrom: (15.1.13 swift-storage)
  • Revision ID: adamg@canonical.com-20130107232553-i0k0u397vhe6ke1d
Merge swift-storage rewrite work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/bash
2
2
# test
3
 
set -u
4
 
FORMULA_DIR=$(dirname $0)
 
3
set -eu
 
4
 
 
5
CHARM_DIR=$(dirname $0)
5
6
ARG0=${0##*/}
6
7
 
7
 
echo $JUJU_UNIT_NAME >>/tmp/unit_name
8
 
 
9
 
if [[ -e $FORMULA_DIR/swift-storage-node-common ]] ; then
10
 
  . $FORMULA_DIR/swift-storage-node-common
 
8
if [[ -e $CHARM_DIR/swift-storage-node-common ]] ; then
 
9
  . $CHARM_DIR/swift-storage-node-common
11
10
else
12
 
  echo "ERROR: Could not load swift-storage-node-common from $FORMULA_DIR"
 
11
  echo "ERROR: Could not load swift-storage-node-common from $CHARM_DIR"
13
12
fi
14
13
 
15
14
function install_hook {
16
 
  ### CANONICAL-SPECIFIC BEGIN ###
17
 
  # MAAS preseed is forcing apt to proxy through the deb caching proxy
18
 
  # on the MAAS server.  This is preventing us from getting to
19
 
  # cloud-archive.  Stop it.
20
 
  rm -f /etc/apt/apt.conf
21
 
  ### CANONICAL-SPECIFIC END ###
22
 
 
23
15
  apt-get -y --force-yes install python-software-properties || exit 1
24
 
  add_ppa
 
16
 
 
17
  configure_install_source "$OPENSTACK_ORIGIN"
25
18
  apt-get update
26
 
  for i in $PACKAGES ; do
27
 
    DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install $i
28
 
  done
 
19
 
 
20
  DEBIAN_FRONTEND=noninteractive apt-get -y \
 
21
    install --no-install-recommends $PACKAGES || exit 1
 
22
 
29
23
  [[ ! -d /etc/swift ]] && mkdir /etc/swift
30
24
  chown swift:swift /etc/swift
31
25
  configure_rsyncd
 
26
  swift-init all stop || true
32
27
  setup_storage
33
 
  for i in account container object ; do create_server_conf $i ; done
 
28
  for i in account container object ; do
 
29
    port=$(config-get ${i}-server-port)
 
30
    create_server_conf $i "$port"
 
31
  done
34
32
}
35
33
 
36
 
function proxy_joined {
37
 
  RELDEVICES=""
38
 
  for DEVICE in $DEVICES; do
39
 
    SRVNODENAME="$(echo $DEVICE | sed 's/[\/:]/-/g')"
40
 
    if [ -n "$RELDEVICES" ]; then
41
 
      RELDEVICES="$RELDEVICES:$SRVNODENAME"
 
34
function storage_joined {
 
35
  local devs=$(determine_block_devs)
 
36
  local reldevices=""
 
37
  for dev in $devs ; do
 
38
    local srvnodename=$(basename $dev)
 
39
    if [[ -n "$reldevices" ]] ; then
 
40
      reldevices="$reldevices:$srvnodename"
42
41
    else
43
 
      RELDEVICES="$SRVNODENAME"
 
42
      reldevices="$srvnodename"
44
43
    fi
45
44
  done
46
 
  relation-set zone=1 hostname=$(unit-get private-address) device=$RELDEVICES
 
45
  relation-set zone="$(config-get zone)" \
 
46
               device="$reldevices" \
 
47
               object_port="$(config-get object-server-port)" \
 
48
               container_port="$(config-get container-server-port)" \
 
49
               account_port="$(config-get account-server-port)"
47
50
}
48
51
 
49
 
function proxy_changed {
50
 
  URL=`relation-get update_url`
51
 
  SWIFT_HASH=`relation-get swift_hash`
52
 
  [[ -z $URL ]] || [[ -z $SWIFT_HASH ]] && exit 0
53
 
  echo "$URL" >>/tmp/url
54
 
  rm -rf /etc/swift/*.gz
 
52
function storage_changed {
 
53
  local www_dir=`relation-get www_dir`
 
54
  local swift_hash=`relation-get swift_hash`
 
55
  [[ -z $www_dir ]] || [[ -z $swift_hash ]] && exit 0
 
56
 
 
57
  set_swift_hash $swift_hash
 
58
  local url="http://$(relation-get private-address)/$www_dir"
55
59
  for i in account object container ; do
56
 
    cd /etc/swift
57
 
    echo "Fetching $URL/$i.ring.gz"
58
 
    wget $URL/$i.ring.gz
 
60
    echo "Fetching $www_dir/$i.ring.gz"
 
61
    wget "$url/$i.ring.gz" -O /etc/swift/$i.ring.gz
59
62
  done
60
 
  set_swift_hash $SWIFT_HASH
 
63
  set_swift_hash $swift_hash
61
64
  chown swift -R /etc/swift
62
 
  swift-init all start
 
65
  swift-init all start || true
63
66
}
64
67
 
65
68
case $ARG0 in
66
69
  "install") install_hook ;;
67
70
  "start"|"stop") exit 0 ;;
68
 
  "swift-proxy-relation-joined") proxy_joined ;;
69
 
  "swift-proxy-relation-changed") proxy_changed ;;
 
71
  "swift-storage-relation-joined") storage_joined ;;
 
72
  "swift-storage-relation-changed") storage_changed ;;
70
73
esac