forked from openedx-unsupported/devstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovision.sh
More file actions
executable file
·98 lines (85 loc) · 2.82 KB
/
provision.sh
File metadata and controls
executable file
·98 lines (85 loc) · 2.82 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
# This script will provision the service specified in the first argument,
# or all services if 'all' is passed as the argument.
#
# Service(s) will generally be setup in the following manner
# (but refer to individual ./provision-{service} scripts to be sure):
# 1. Migrations run,
# 2. Tenants—as in multi-tenancy—setup,
# 3. Service users and OAuth clients setup in LMS,
# 4. Static assets compiled/collected.
set -e
set -o pipefail
set -x
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
if [[ $# -ne 1 ]]; then
echo -e "${RED}Exactly one argument required: Name of service or 'all'.\n\
Example 1: ./provision.sh discovery\n\
Example 2: ./provision.sh all${NC}"
exit 1
fi
service=$1
case $service in
all)
echo -e "${GREEN}Will provision all services.${NC}"
service=""
;;
lms|ecommerce|discovery|credentials|e2e|forum|registrar)
echo -e "${GREEN}Will provision one service: ${service}.${NC}"
;;
edx_notes_api)
echo -e "${GREEN}Will Provision edx_notes_api${NC}"
service="notes"
;;
studio)
echo -e "${YELLOW}Studio is provisioned along with LMS; try running './provision.sh lms'${NC}"
exit 0
;;
*)
echo -e "${YELLOW}Service '${service}' either doesn't exist or isn't provisionable. Exiting.${NC}"
exit 1
esac
# Bring the databases online.
docker-compose up -d mysql mongo
# Ensure the MySQL server is online and usable
echo "Waiting for MySQL"
until docker exec -i edx.devstack.mysql mysql -uroot -se "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'root')" &> /dev/null
do
printf "."
sleep 1
done
# In the event of a fresh MySQL container, wait a few seconds for the server to restart
# See https://github.com/docker-library/mysql/issues/245 for why this is necessary.
sleep 20
echo -e "MySQL ready"
# Ensure that the MySQL databases and users are created for all IDAs.
# (A no-op for databases and users that already exist).
echo -e "${GREEN}Ensuring MySQL databases and users exist...${NC}"
docker exec -i edx.devstack.mysql mysql -uroot mysql < provision.sql
# If necessary, ensure the MongoDB server is online and usable
# and create its users.
case $service in
"lms"|"studio"|"forum"|"")
echo "Waiting for MongoDB"
until docker exec -i edx.devstack.mongo mongo --eval "printjson(db.serverStatus())" &> /dev/null
do
printf "."
sleep 1
done
echo -e "MongoDB ready"
echo -e "${GREEN}Creating MongoDB users...${NC}"
docker exec -i edx.devstack.mongo mongo < mongo-provision.js
;;
*)
echo -e "${GREEN}MongoDB preparation not required; skipping.${NC}"
esac
# Run the service-specific provisioning script(s)
for serv in ${service:-lms ecommerce discovery credentials e2e forum notes registrar}; do
echo -e "${GREEN} Provisioning ${serv}...${NC}"
./provision-${serv}.sh
done
docker image prune -f
echo -e "${GREEN}Provisioning complete!${NC}"