-
Notifications
You must be signed in to change notification settings - Fork 3
/
docker-entrypoint.sh
58 lines (48 loc) · 2.01 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
#!/bin/bash
#
# First do all the setup that we could not do in the Dockerfile, since this
# requires input from the docker run command, e.g.:
# - we have remounted volumes due to --volumes-from
set -e
me=`basename -- "$0"`
if [ -z "$KNOWN_MYSQL_PASSWORD" ]; then
echo >&2 "$me: error: The following environment variable must be set:"
echo >&2 "$me: \$KNOWN_MYSQL_PASSWORD"
echo >&2 "$me: Add them using the -e option to docker run"
exit 1
fi
echo "dbpass = '$KNOWN_MYSQL_PASSWORD'" >> /var/www/known/config.ini
# Fix permissions for the uploads directory, since it was mounted by
# --volumes-from when the container was run.
chown -R root:www-data /known/uploads
chmod -R 775 /known/uploads
# The MySQL server is slow to start the very first time you run the mysql
# container, so we have to wait.
# Borrowed from tutum-docker-mysql on GitHub!
LOOP_LIMIT=12
for (( i=0 ; ; i++ )); do
mysql -h mysql -u known -p$KNOWN_MYSQL_PASSWORD -e "status" > \
/dev/null 2>&1 \
&& break
if [ ${i} -eq ${LOOP_LIMIT} ]; then
echo >&2 "$me: error: Timed out waiting for MySQL service to start"
echo >&2 "$me: Double check that you specified the correct MySQL"
echo >&2 "$me: user name and password, and that you --link'ed"
echo >&2 "$me: the MySQL container using alias: mysql"
exit 2
fi
echo "$me: Waiting for MySQL service to start... ($((i*5))/$((LOOP_LIMIT*5)) seconds)"
sleep 5
done
echo "$me: Successfully connected to MySQL service"
# We could not init the DB in the Dockerfile, since then we were not yet
# --link'ed to the MySQL container, so do it now. This is idempotent, so it's
# ok to do it every time we run a container even though the DB is in a volume.
mysql -h mysql -u known -p$KNOWN_MYSQL_PASSWORD known \
< /var/www/known/warmup/schemas/mysql/mysql.sql
source /etc/apache2/envvars
if [ -f "$APACHE_PID_FILE" ]; then
echo "$me: warning: removing existing Apache PID file: $APACHE_PID_FILE"
rm -f "$APACHE_PID_FILE"
fi
exec "$@"