forked from docker-library/php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapache2-foreground
executable file
·56 lines (48 loc) · 2.17 KB
/
apache2-foreground
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
#!/bin/bash
set -e
# Note: we don't just use "apache2ctl" here because it itself is just a shell-script wrapper around apache2 which provides extra functionality like "apache2ctl start" for launching apache2 in the background.
# (also, when run as "apache2ctl <apache args>", it does not use "exec", which leaves an undesirable resident shell process)
# Default SSL directory
SSL_DIR=${APACHE_SSL_DIR:-/etc/apache2/ssl}
# Create the directory if it doesn't exist
# Check and decode the certificate and key
if [ -n "$APACHE_CERT_BASE64" ] && [ -n "$APACHE_KEY_BASE64" ]; then
mkdir -p "$SSL_DIR"
echo "$APACHE_CERT_BASE64" | base64 -d > "$SSL_DIR/apache-cert.pem.crt"
echo "$APACHE_KEY_BASE64" | base64 -d > "$SSL_DIR/apache-key.pem.key"
sed -i "s|/etc/ssl/certs/ssl-cert-snakeoil.pem|$SSL_DIR/apache-cert.pem.crt|g" /etc/apache2/sites-available/default-ssl.conf
sed -i "s|/etc/ssl/private/ssl-cert-snakeoil.key|$SSL_DIR/apache-key.pem.key|g" /etc/apache2/sites-available/default-ssl.conf
ln -s /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/default-ssl.conf
chmod 0755 "$SSL_DIR/apache-cert.pem.crt" "$SSL_DIR/apache-key.pem.key" /etc/apache2/sites-enabled/default-ssl.conf
a2enmod ssl
fi
: "${APACHE_CONFDIR:=/etc/apache2}"
: "${APACHE_ENVVARS:=$APACHE_CONFDIR/envvars}"
if test -f "$APACHE_ENVVARS"; then
. "$APACHE_ENVVARS"
fi
# Apache gets grumpy about PID files pre-existing
: "${APACHE_RUN_DIR:=/var/run/apache2}"
: "${APACHE_PID_FILE:=$APACHE_RUN_DIR/apache2.pid}"
rm -f "$APACHE_PID_FILE"
# create missing directories
# (especially APACHE_RUN_DIR, APACHE_LOCK_DIR, and APACHE_LOG_DIR)
for e in "${!APACHE_@}"; do
if [[ "$e" == *_DIR ]] && [[ "${!e}" == /* ]]; then
# handle "/var/lock" being a symlink to "/run/lock", but "/run/lock" not existing beforehand, so "/var/lock/something" fails to mkdir
# mkdir: cannot create directory '/var/lock': File exists
dir="${!e}"
while [ "$dir" != "$(dirname "$dir")" ]; do
dir="$(dirname "$dir")"
if [ -d "$dir" ]; then
break
fi
absDir="$(readlink -f "$dir" 2>/dev/null || :)"
if [ -n "$absDir" ]; then
mkdir -p "$absDir"
fi
done
mkdir -p "${!e}"
fi
done
exec apache2 -DFOREGROUND "$@"