Added seed code for caas-registry.
[ta/caas-registry.git] / docker-build / swift / mainstart.sh
1 #!/bin/sh
2 # Copyright 2019 Nokia
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 #Before start:
17 #Part power, replica and hour as env
18
19 if [ $1 == "BACKEND_BUILDER" ]; then
20   echo "Remove unnecessary pid file"
21   rm -rf /var/run/rsyncd/rsyncd.pid
22 fi
23
24 file_names="/etc/swift/account-server.conf /etc/swift/container-server.conf /etc/swift/object-server.conf /etc/swift/proxy-server.conf /etc/swift/rsyncd.conf /etc/swift/swift.conf /etc/swift/memcached"
25 /usr/bin/wait-for-files "${file_names}"
26 rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
27
28 if [ ! -e /etc/swift/account.ring.gz ]; then
29   cd /etc/swift
30   echo "Ring files not found. Create them..."
31   # get ports from the config files
32   SWIFT_ACCOUNT_PORT=`grep "bind_port" /etc/swift/account-server.conf | awk '{print $3}'`
33   SWIFT_CONTAINER_PORT=`grep "bind_port" /etc/swift/container-server.conf | awk '{print $3}'`
34   SWIFT_OBJECT_PORT=`grep "bind_port" /etc/swift/object-server.conf | awk '{print $3}'`
35
36   swift-ring-builder account.builder create ${SWIFT_PART_POWER} ${SWIFT_REPLICAS} ${SWIFT_PART_HOUR}
37   swift-ring-builder container.builder create ${SWIFT_PART_POWER} ${SWIFT_REPLICAS} ${SWIFT_PART_HOUR}
38   swift-ring-builder object.builder create ${SWIFT_PART_POWER} ${SWIFT_REPLICAS} ${SWIFT_PART_HOUR}
39
40   for IP in ${SWIFT_OAM1_IP} ${SWIFT_OAM2_IP} ${SWIFT_OAM3_IP}; do
41     swift-ring-builder account.builder add r1z2-$IP:${SWIFT_ACCOUNT_PORT}/${SWIFT_DISK} 10
42     swift-ring-builder container.builder add r1z2-$IP:${SWIFT_CONTAINER_PORT}/${SWIFT_DISK} 10
43     swift-ring-builder object.builder add r1z2-$IP:${SWIFT_OBJECT_PORT}/${SWIFT_DISK} 10
44     echo "swift-ring-builder object.builder add r1z2-$IP:6000/${SWIFT_DISK} 10"
45   done
46
47   swift-ring-builder account.builder
48   swift-ring-builder container.builder
49   swift-ring-builder object.builder
50
51   swift-ring-builder account.builder rebalance
52   swift-ring-builder container.builder rebalance
53   swift-ring-builder object.builder rebalance
54 fi
55
56 exec /usr/bin/supervisord -c /etc/supervisord.conf