forked from solidnerd/docker-bookstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·70 lines (57 loc) · 1.68 KB
/
docker-entrypoint.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
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
#!/bin/bash
set -e
echoerr() { echo "$@" 1>&2; }
check_vars_exist() {
var_names=("$@")
for var_name in "${var_names[@]}"; do
if [ -z "${!var_name}" ]; then
echoerr "error: missing ${var_name} environment variable"
exit 1
fi
done
}
# Split out host and port from DB_HOST env variable
IFS=":" read -r DB_HOST_NAME DB_PORT <<< "$DB_HOST"
DB_PORT=${DB_PORT:-3306}
# Ensure there is no local .env file
if [ -f ".env" ]; then
mv .env .env.bak
echoerr ".env file detected - moved to .env.bak"
echoerr "Please update your configuration to use environment variables in the container!"
fi
# Check a number of essential variables are set
check_vars_exist \
APP_KEY \
APP_URL \
DB_DATABASE \
DB_HOST \
DB_PASSWORD \
DB_PORT \
DB_USERNAME
if [ -n "${FILE_UPLOAD_SIZE_LIMITS}" ]; then
echo "Note: If you're setting FILE_UPLOAD_SIZE_LIMITS to more than 10M, you"
echo "may also need to modify the php.ini file."
echo "See:"
echo "https://github.com/solidnerd/docker-bookstack/issues/423"
fi
echoerr "wait-for-db: waiting for ${DB_HOST_NAME}:${DB_PORT}"
timeout 15 bash <<EOT
while ! (echo > /dev/tcp/${DB_HOST_NAME}/${DB_PORT}) >/dev/null 2>&1;
do sleep 1;
done;
EOT
RESULT=$?
if [ $RESULT -eq 0 ]; then
# sleep another second for so that we don't get a "the database system is starting up" error
sleep 1
echoerr "wait-for-db: done"
else
echoerr "wait-for-db: timeout out after 15 seconds waiting for ${DB_HOST_NAME}:${DB_PORT}"
fi
echo "Starting Migration..."
php artisan migrate --force
echo "Clearing caches..."
php artisan cache:clear
php artisan view:clear
trap "echo Catching SIGWINCH apache error and perventing it." SIGWINCH
exec apache2-foreground