-
Notifications
You must be signed in to change notification settings - Fork 5
/
docker-entrypoint.sh
executable file
·84 lines (65 loc) · 2.72 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
set -e
if [ "$USER" = "root" ]; then
# set localtime
ln -sf /usr/share/zoneinfo/$LOCALTIME /etc/localtime
# secure path
chmod a-rwx -R /etc/apache2/ $PHP_INI_DIR/ /etc/ssmtp
fi
#
# functions
function set_conf {
echo ''>$2; IFSO=$IFS; IFS=$(echo -en "\n\b")
for c in `printenv|grep $1`; do echo "`echo $c|cut -d "=" -f1|awk -F"$1" '{print $2}'` $3 `echo $c|cut -d "=" -f2`" >> $2; done;
IFS=$IFSO
}
#
# APACHE
if [ ! -d "$HTTPD__DocumentRoot" ]; then echo >&2 "[Error] Document Root Directory not exist (please create $HTTPD__DocumentRoot)"; exit 1; fi
if [ "$HTTPD_a2enmod" != "" ]; then a2enmod $HTTPD_a2enmod > /dev/null; fi;
set_conf "HTTPD__" "$HTTPD_CONF_DIR/40-user.conf" ""
#
# PHP
echo "date.timezone = \"${LOCALTIME}\"" >> $PHP_INI_DIR/conf.d/00-default.ini
if [ "$PHP_php5enmod" != "" ]; then docker-php-ext-enable $PHP_php5enmod > /dev/null 2>&1; fi;
set_conf "PHP__" "$PHP_INI_DIR/conf.d/40-user.ini" "="
#
# docker links
# Deprecated - Set memcached server with link
if [ -n "$PHP_MEMCACHED_PORT_11211_TCP_ADDR" ]; then
echo "[WARNING] Deprecated - Future versions of Docker will not support links - you should remove them for forwards-compatibility."
echo "session.save_handler = memcached" > $PHP_INI_DIR/conf.d/20-memcached.ini
echo "session.save_path = $PHP_MEMCACHED_PORT_11211_TCP_ADDR:$PHP_MEMCACHED_PORT_11211_TCP_PORT" >> $PHP_INI_DIR/conf.d/20-memcached.ini
elif [ -f $PHP_INI_DIR/conf.d/20-memcached.ini ]; then
rm $PHP_INI_DIR/conf.d/20-memcached.ini
fi
# Deprecated - Set ssmtp server with link
if [ -n "$SMTP_PORT_25_TCP_ADDR" ]; then
echo "[WARNING] Deprecated - Future versions of Docker will not support links - you should remove them for forwards-compatibility."
echo 'sendmail_path = /usr/sbin/ssmtp -t' >> $PHP_INI_DIR/conf.d/00-default.ini
sed -i "s/mailhub=.*/mailhub=$SMTP_PORT_25_TCP_ADDR:$SMTP_PORT_25_TCP_PORT/" /etc/ssmtp/ssmtp.conf
fi
# Set memcached session save handle
if [ -n "$MEMCACHED" ]; then
if [ ! -f $PHP_INI_DIR/conf.d/docker-php-ext-memcached.ini ]; then docker-php-ext-enable memcached > /dev/null; fi
IFSO=$IFS; IFS=' ' read -ra BACKENDS <<< "${MEMCACHED}"
for BACKEND in "${BACKENDS[@]}"; do
SAVE_PATH="${SAVE_PATH}${BACKEND}?${MEMCACHED_CONFIG:-persistent=1&timeout=5&retry_interval=30},"
done; IFS=$IFSO;
cat << EOF >> $PHP_INI_DIR/conf.d/20-memcached.ini
session.save_handler = memcached
session.save_path = "${SAVE_PATH}"
EOF
fi
# Set ssmtp server
if [ -n "$SMTP" ]; then
echo 'sendmail_path = /usr/sbin/ssmtp -t' >> $PHP_INI_DIR/conf.d/00-default.ini
sed -i "s/mailhub=.*/mailhub=${SMTP}/" /etc/ssmtp/ssmtp.conf
fi
#
# Run
if [[ $# -eq 0 ]]; then
exec apache2-foreground
else
exec "$@"
fi