-
Notifications
You must be signed in to change notification settings - Fork 17
/
create-cloudgov-services.sh
executable file
·40 lines (32 loc) · 1.82 KB
/
create-cloudgov-services.sh
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
#!/bin/sh
set -e
# If an argument was provided, use it as the service name prefix.
# Otherwise default to "catalog".
app_name=${1:-catalog}
# Get the current space and trim leading whitespace
space=$(cf target | grep space | cut -d : -f 2 | xargs)
# Production and staging should use bigger DB and Redis instances
if [ "$space" = "prod" ] || [ "$space" = "staging" ]; then
cf service "${app_name}-db" > /dev/null 2>&1 || cf create-service aws-rds medium-psql-redundant "${app_name}-db" --wait&
cf service "${app_name}-redis" > /dev/null 2>&1 || cf create-service aws-elasticache-redis redis-3node "${app_name}-redis" --wait&
else
cf service "${app_name}-db" > /dev/null 2>&1 || cf create-service aws-rds small-psql "${app_name}-db" --wait&
cf service "${app_name}-redis" > /dev/null 2>&1 || cf create-service aws-elasticache-redis redis-dev "${app_name}-redis" --wait&
fi
# TODO: update if and when the service broker reverts to `ssb-solr-gsa-datagov-<space>`
cf service "${app_name}-solr" > /dev/null 2>&1 || cf create-service solr-on-ecs base "${app_name}-solr" -c solr/service-config-${space}.json -b "ssb-solrcloud-gsa-datagov-${space}" --wait&
cf service "${app_name}-smtp" > /dev/null 2>&1 || cf create-service datagov-smtp base "${app_name}-smtp" -c smtp/service-config-${space}.json -b "ssb-smtp-gsa-datagov-${space}" --wait&
# Wait until all the services are ready
wait
# Check that all the services are in a healthy state. (The OSBAPI spec says that
# the "last operation" should include "succeeded".)
success=0;
for service in "${app_name}-db" "${app_name}-redis" "${app_name}-solr"
do
status=$(cf service "$service" | grep 'status:\s*.\+$' )
echo "$service $status"
if ! echo "$status" | grep -q 'succeeded' ; then
success=1;
fi
done
exit $success