forked from dokku-alt/dokku-alt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdokku_common_database
More file actions
55 lines (48 loc) · 1.56 KB
/
Copy pathdokku_common_database
File metadata and controls
55 lines (48 loc) · 1.56 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
#!/bin/bash
function start_database_container() {
if ! docker inspect "$DB_CONTAINER" >/dev/null 2>/dev/null; then
# Create data directory if does not exist
if [[ ! -d "$DB_ROOT" ]]; then
mkdir -p "$DB_ROOT"
chown -R dokku: "$DB_ROOT"
fi
# Create root password if not specified
if [[ ! -f "$DB_ADMIN_PASSWORD" ]]; then
generate_random_password > "$DB_ADMIN_PASSWORD"
fi
# Start database container
docker run --detach \
--name="$DB_CONTAINER" \
--volume="$DB_VOLUME":"$DB_CONTAINER_VOLUME" \
--volume="$DB_ADMIN_PASSWORD":"$DB_CONTAINER_PASSWORD" \
"$DB_IMAGE" \
"$DB_COMMAND" >/dev/null
fi
for i in $(seq 1 100); do
if [[ -f "$DB_VOLUME/initialized" ]]; then
break
fi
echo "Waiting for $DB_HOST to boot ($i)..."
sleep 5s
done
}
function restart_database_container() {
stop_and_remove_container "$DB_CONTAINER"
start_database_container
}
function ensure_database_container_is_running() {
remove_container "$DB_CONTAINER"
start_database_container
}
function db_info() {
APP="$1"
DB_NAME="$2"
DB_PASSWORD="$DB_APP_PASSWORDS$APP"
DB_LINK="$DB_APP_DATABASES$APP/$DB_NAME"
DB_PASSWORD="$(cat "$DB_PASSWORD" 2>/dev/null)"
DB_USER="$APP"
DB_DATABASE="$DB_NAME"
DB_URL="$DB_PROTOCOL://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_DATABASE"
[[ ! -f "$DB_LINK" ]] && return 1
return 0
}