summaryrefslogtreecommitdiff
path: root/swift-storage.configure
blob: 19930bbb1f35b06ff0ed82b0447810eea7329c9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#
# Copyright © 2015 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

set -e

# The ansible script needs to know where the rootfs is, so we export it here
export ROOT="$1"

validate_number() {
    if ! echo -n "$2" | grep -xq '[0-9]\+'
    then
        echo "'$1' must be a number" >&2
        exit 1
    fi
}

validate_non_empty() {
    if [[ "$2" = None ]]
    then
        echo "'$1' cannot be empty" >&2
        exit 1
    fi
}

MANDATORY_OPTIONS="SWIFT_HASH_PATH_PREFIX SWIFT_HASH_PATH_SUFFIX SWIFT_REBALANCE_SEED
SWIFT_PART_POWER SWIFT_REPLICAS SWIFT_MIN_PART_HOURS SWIFT_STORAGE_DEVICES MANAGEMENT_INTERFACE_IP_ADDRESS"

for option in $MANDATORY_OPTIONS
do
    if ! [[ -v $option ]]
    then
        missing_option=True
        echo "Required option $option isn't set!" >&2
    fi
done

if [[ "$missing_option" = True ]]; then exit 1; fi

./swift-storage-devices-validate.py "$SWIFT_STORAGE_DEVICES"

# Validate SWIFT_PART_POWER, SWIFT_REPLICAS, SWIFT_MIN_PART_HOURS
# just make sure they're numbers

validate_number "SWIFT_PART_POWER" "$SWIFT_PART_POWER"
validate_number "SWIFT_REPLICAS" "$SWIFT_REPLICAS"
validate_number "SWIFT_MIN_PART_HOURS" "$SWIFT_MIN_PART_HOURS"

# Make sure these aren't empty
validate_non_empty "SWIFT_HASH_PATH_PREFIX" "$SWIFT_HASH_PATH_PREFIX"
validate_non_empty "SWIFT_HASH_PATH_SUFFIX" "$SWIFT_HASH_PATH_SUFFIX"
validate_non_empty "SWIFT_REBALANCE_SEED" "$SWIFT_REBALANCE_SEED"
validate_non_empty "MANAGEMENT_INTERFACE_IP_ADDRESS" "$MANAGEMENT_INTERFACE_IP_ADDRESS"

mkdir -p "$ROOT/usr/lib/systemd/system/multi-user.target.wants" # ensure this exists before we make symlinks

ln -s "/usr/lib/systemd/system/rsync.service" \
    "$ROOT/usr/lib/systemd/system/multi-user.target.wants/rsync.service"
ln -s "/usr/lib/systemd/system/swift-storage.service" \
    "$ROOT/usr/lib/systemd/system/multi-user.target.wants/swift-storage.service"
ln -s "/usr/lib/systemd/system/swift-storage-setup.service" \
    "$ROOT/usr/lib/systemd/system/multi-user.target.wants/swift-storage-setup.service"

# Build swift data structures (the rings)
/usr/bin/ansible-playbook -i hosts swift-build-rings.yml

cat << EOF > "$ROOT"/usr/share/swift/swift-storage-vars.yml
---
MANAGEMENT_INTERFACE_IP_ADDRESS: $MANAGEMENT_INTERFACE_IP_ADDRESS
SWIFT_HASH_PATH_PREFIX: $SWIFT_HASH_PATH_PREFIX
SWIFT_HASH_PATH_SUFFIX: $SWIFT_HASH_PATH_SUFFIX
EOF