This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apache2-foreground-user
executable file
·216 lines (187 loc) · 6.71 KB
/
apache2-foreground-user
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
set -e
if [ -n "$WARNING" ]; then
echo "$WARNING" >&2
fi
function var_default {
if [ -z "${!1}" ]; then
export $1="$2"
fi
}
function ini_line {
if [ ! -z "$2" ]; then
if [ -z "$3" ]; then
echo "$1 = \"$2\""
else
echo "$1 = \"$2\"" >> $3
fi
fi
}
var_default APP_DATA /app/data
var_default PHP_MAIL_FROM john.doe@example.com
var_default PHP_MAIL_HOST mail
var_default PHP_SESSION_SAVE_PATH "${APP_DATA}/session"
var_default PHP_UPLOAD_TMP_DIR "${APP_DATA}/upload_tmp"
var_default PHP_UPLOAD_MAX_FILESIZE 64M
var_default PHP_POST_MAX_SIZE 64M
var_default PHP_PCRE_JIT 1
var_default PHPINI_EXPOSE_PHP off
if [ -e "/usr/local/bin/apache2-foreground" ]; then
var_default FINAL_EXEC /usr/local/bin/apache2-foreground
else
var_default FINAL_EXEC php-fpm
fi
if [ ! -f "/state/init_done" ]; then
echo "Creating config..."
SENDMAIL_INI=/usr/local/etc/php/conf.d/sendmail.ini
ini_line sendmail_from "${PHP_MAIL_FROM}" $SENDMAIL_INI
if [ -z "${PHP_MAIL_MSMTP_OPTIONS}" ]; then
ini_line sendmail_path "/usr/bin/msmtp --host=${PHP_MAIL_HOST} --from=${PHP_MAIL_FROM} --auth=off -t" $SENDMAIL_INI
else
ini_line sendmail_path "/usr/bin/msmtp ${PHP_MAIL_MSMTP_OPTIONS}" $SENDMAIL_INI
fi
cat $SENDMAIL_INI
DOCKER_INI=/usr/local/etc/php/conf.d/docker-php.ini
ini_line session.save_path "$PHP_SESSION_SAVE_PATH" $DOCKER_INI
ini_line upload_tmp_dir "$PHP_UPLOAD_TMP_DIR" $DOCKER_INI
ini_line upload_max_filesize "$PHP_UPLOAD_MAX_FILESIZE" $DOCKER_INI
ini_line post_max_size "$PHP_POST_MAX_SIZE" $DOCKER_INI
ini_line pcre.jit "$PHP_PCRE_JIT" $DOCKER_INI
ini_line memory_limit "$PHP_MEMORY_LIMIT" $DOCKER_INI
ini_line date.timezone "$PHP_DATE_TIMEZONE" $DOCKER_INI
ini_line short_open_tag "$PHP_SHORT_OPEN_TAG" $DOCKER_INI
if [ -n "$PHP_EXTENSIONS" ]; then
for EXT in $PHP_EXTENSIONS; do
echo "extension=$EXT" >> $DOCKER_INI
done
fi
if [ -n "$PHP_ZEND_EXTENSIONS" ]; then
for EXT in $PHP_ZEND_EXTENSIONS; do
echo "zend_extension=$EXT" >> $DOCKER_INI
done
fi
# Any environment variable starting with PHPINI_ will be transformed to an
# ini setting. "__" will by replaced by ".". ex. "PHPINI_FOO__BAR_X" -> "foo.bar_x"
while IFS= read -r -d '' ENVVAR; do
if [[ $ENVVAR == PHPINI_* ]] ; then
IFS='=' read -ra ENVNAME <<< "$ENVVAR"
PHPNAME=${ENVNAME,,}
PHPNAME=${PHPNAME:7}
PHPNAME=${PHPNAME//__/.}
echo "$PHPNAME = \"${!ENVNAME}\"" >> $DOCKER_INI
fi
done < <(env -0)
cat $DOCKER_INI
if [ ! -z "$ROBOTS_DISALLOW" ]; then
echo "Robots disallow: ${ROBOTS_DISALLOW}"
echo "User-agent: *" > $WEB_ROOT/robots.txt
echo "Disallow: $ROBOTS_DISALLOW" >> $WEB_ROOT/robots.txt
fi
if [ ! -z "$PHP_TYPO3_INI" ]; then
>&2 echo "DEPRECATION: PHP_TYPO3_INI variable will be removed in the future of this image!"
TYPO3_INI=/usr/local/etc/php/conf.d/typo3.ini
ini_line always_populate_raw_post_data "-1" $TYPO3_INI
ini_line max_input_vars "1500" $TYPO3_INI
ini_line max_execution_time "240" $TYPO3_INI
cat $TYPO3_INI
fi
OPCACHE_INI=/usr/local/etc/php/conf.d/docker-php-ext-opcache-extra.ini
if [ ! -z "$PHP_OPCACHE_INI" ]; then
>&2 echo "DEPRECATION: PHP_OPCACHE_INI variable will be removed in the future of this image!"
echo "opcache enabled"
ini_line opcache.fast_shutdown "$PHP_OPCACHE_INI_FAST_SHOTDOWN" $OPCACHE_INI # just to be compatible with this typo
ini_line opcache.fast_shutdown "$PHP_OPCACHE_INI_FAST_SHUTDOWN" $OPCACHE_INI
ini_line opcache.max_accelerated_files "$PHP_OPCACHE_INI_MAX_ACCELERATED_FILES" $OPCACHE_INI
ini_line opcache.interned_strings_buffer "$PHP_OPCACHE_INI_INTERNED_STRINGS_BUFFER" $OPCACHE_INI
ini_line opcache.memory_consumption "$PHP_OPCACHE_INI_MEMORY_CONSUMPTION" $OPCACHE_INI
ini_line opcache.revalidate_freq "$PHP_OPCACHE_INI_REVALIDATE_FREQ" $OPCACHE_INI
ini_line opcache.file_cache "$PHP_OPCACHE_INI_FILE_CACHE" $OPCACHE_INI
if [ -e "$OPCACHE_INI" ]; then
cat $OPCACHE_INI
fi
else
echo "opcache disabled"
rm -f $OPCACHE_INI
fi
if [ ! -z "$SALLY_CLEAR_CACHE" ]; then
>&2 echo "DEPRECATION: SALLY_CLEAR_CACHE variable will be removed in the future of this image!"
echo "clear sally yaml and less cache"
rm -rf "${APP_DATA}/temp/sally/yaml-cache/*"
rm -rf "${APP_DATA}/temp/sally/less-cache/*"
fi
mkdir -p "$PHP_UPLOAD_TMP_DIR"
mkdir -p "$PHP_SESSION_SAVE_PATH"
if [ ! -z "$STARTUP_CREATE_DIRS" ]; then
echo "create directories: ${STARTUP_CREATE_DIRS}"
mkdir -p $STARTUP_CREATE_DIRS
fi
if [ ! -z "$WWW_USER" ]; then
export APACHE_RUN_USER="$WWW_USER"
echo "APACHE_RUN_USER: $WWW_USER"
if [ $(id -u $WWW_USER 2>/dev/null || echo -1) -lt 0 ]; then
echo "User does not exist"
exit -1
fi
fi
if [ ! -z "$WWW_GROUP" ]; then
export APACHE_RUN_GROUP="$WWW_GROUP"
echo "APACHE_RUN_GROUP: $WWW_GROUP"
if [ $(id -g $WWW_GROUP 2>/dev/null || echo -1) -lt 0 ]; then
echo "Group does not exist"
exit -1
fi
fi
if [ ! -z "$APP_DATA_DENY" ]; then
echo "Deny all: ${APP_DATA}"
echo "Require all denied" > "${APP_DATA}/.htaccess"
fi
if [ ! -z "$STARTUP_CHOWN" ]; then
echo "chown: ${STARTUP_CHOWN}"
chown ${WWW_USER-www-data}:${WWW_GROUP-www-data} $STARTUP_CHOWN
fi
if [ ! -z "$STARTUP_CHOWN_RECURSIVE" ]; then
echo "chown -R: ${STARTUP_CHOWN_RECURSIVE}"
chown ${WWW_USER-www-data}:${WWW_GROUP-www-data} $STARTUP_CHOWN_RECURSIVE
fi
if [ ! -z "$STARTUP_REMOVE" ]; then
echo "rm -rf: ${STARTUP_REMOVE}"
rm -rf $STARTUP_REMOVE
fi
if [ ! -z "$SecExclude" ]; then
echo "$SecExclude" >> /usr/share/modsecurity-crs/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS-DOCKER.conf
echo "ModSecurity exclusion: "
echo "$SecExclude"
fi
touch "/state/init_done"
else
echo "Skipping config creation because caintainer is restarted."
if [ ! -z "$WWW_USER" ]; then
export APACHE_RUN_USER="$WWW_USER"
echo "APACHE_RUN_USER: $WWW_USER"
fi
if [ ! -z "$WWW_GROUP" ]; then
export APACHE_RUN_GROUP="$WWW_GROUP"
echo "APACHE_RUN_GROUP: $WWW_GROUP"
fi
fi
if [ ! -z "$START_SCRIPT_DIR" ]; then
for SCRIPT in $START_SCRIPT_DIR/*
do
if [ -f $SCRIPT -a -x $SCRIPT ]
then
$SCRIPT
fi
done
fi
if [ ! -z "$MINICRON_EXEC" ]; then
echo "Running minicron..."
if [ ! -z "$MINICRON_CRONTAB" ]; then
exec minicron -e <<< "$MINICRON_CRONTAB"
fi
if [ ! -z "$MINICRON_FILE" ]; then
cat "$MINICRON_FILE" | exec minicron -e
fi
echo "Missing MINICRON_CRONTAB or MINICRON_FILE env variable"
exit -1
fi
exec "$FINAL_EXEC"