Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit de79a2b

Browse files
committed
Merge pull request #48 from jdeathe/issue/46
ISSUE 46: Implement HTTPD environment variable.
2 parents 3e2abd4 + 80941b4 commit de79a2b

File tree

7 files changed

+52
-22
lines changed

7 files changed

+52
-22
lines changed

Dockerfile

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ RUN sed -i \
3535
-e 's~^;cgi.fix_pathinfo=1$~cgi.fix_pathinfo=1~g' \
3636
/etc/php.ini
3737

38-
# -----------------------------------------------------------------------------
39-
# Enable Apache MPM worker
40-
# -----------------------------------------------------------------------------
41-
RUN sed -i \
42-
-e 's~#HTTPD=/usr/sbin/httpd.worker~HTTPD=/usr/sbin/httpd.worker~g' \
43-
/etc/sysconfig/httpd
44-
4538
# -----------------------------------------------------------------------------
4639
# Disable mod_php
4740
# -----------------------------------------------------------------------------
@@ -65,6 +58,29 @@ RUN ln -sf /etc/services-config/httpd/apache-bootstrap.conf /etc/apache-bootstra
6558
&& ln -sf /etc/services-config/httpd/conf.d/fcgid.conf /etc/httpd/conf.d/fcgid.conf \
6659
&& chmod +x /etc/apache-bootstrap
6760

61+
# -----------------------------------------------------------------------------
62+
# Set default environment variables used to identify the service container
63+
# -----------------------------------------------------------------------------
64+
ENV SERVICE_UNIT_APP_GROUP app-1
65+
ENV SERVICE_UNIT_LOCAL_ID 1
66+
ENV SERVICE_UNIT_INSTANCE 1
67+
68+
# -----------------------------------------------------------------------------
69+
# Set default environment variables used to configure the service container
70+
# -----------------------------------------------------------------------------
71+
ENV APACHE_EXTENDED_STATUS_ENABLED false
72+
ENV APACHE_LOAD_MODULES "authz_user_module log_config_module expires_module deflate_module headers_module setenvif_module mime_module status_module dir_module alias_module"
73+
ENV APACHE_MOD_SSL_ENABLED false
74+
ENV APACHE_SERVER_ALIAS ""
75+
ENV APACHE_SERVER_NAME app-1.local
76+
ENV APP_HOME_DIR /var/www/app
77+
ENV DATE_TIMEZONE UTC
78+
ENV HTTPD /usr/sbin/httpd.worker
79+
ENV SERVICE_USER app
80+
ENV SERVICE_USER_GROUP app-www
81+
ENV SERVICE_USER_PASSWORD ""
82+
ENV SUEXECUSERGROUP false
83+
6884
EXPOSE 80 8443 443
6985

7086
CMD ["/usr/bin/supervisord", "--configuration=/etc/supervisord.conf"]

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This build of [Apache](https://httpd.apache.org/), (httpd CentOS package), uses
1313

1414
Included in the build are the [EPEL](http://fedoraproject.org/wiki/EPEL) and [IUS](https://ius.io/) repositories. Installed packages include [OpenSSH](http://www.openssh.com/portable.html) secure shell, [vim-minimal](http://www.vim.org/), [elinks](http://elinks.or.cz) (for fullstatus support), PHP [APC](http://pecl.php.net/package/APC), PHP [Memcached](http://pecl.php.net/package/memcached) are installed along with python-setuptools, [supervisor](http://supervisord.org/) and [supervisor-stdout](https://github.com/coderanger/supervisor-stdout).
1515

16-
Supervisor is used to start httpd.worker daemon when a docker container based on this image is run. To enable simple viewing of stdout for the sshd subprocess, supervisor-stdout is included. This allows you to see output from the supervisord controlled subprocesses with ```docker logs <docker-container-name>```.
16+
Supervisor is used to start httpd.worker daemon when a docker container based on this image is run. To enable simple viewing of stdout for the service's subprocess, supervisor-stdout is included. This allows you to see output from the supervisord controlled subprocesses with ```docker logs <docker-container-name>```.
1717

1818
If enabling and configuring SSH access, it is by public key authentication and, by default, the [Vagrant](http://www.vagrantup.com/) [insecure private key](https://github.com/mitchellh/vagrant/blob/master/keys/vagrant) is required.
1919

@@ -38,7 +38,6 @@ $ docker run -d \
3838
--env "SERVICE_UNIT_APP_GROUP=app-1" \
3939
--env "SERVICE_UNIT_LOCAL_ID=1" \
4040
--env "SERVICE_UNIT_INSTANCE=1" \
41-
--env "APACHE_SERVER_ALIAS=app-1" \
4241
--env "APACHE_SERVER_NAME=app-1.local" \
4342
--env "DATE_TIMEZONE=UTC" \
4443
-v /var/services-data/apache-php/app-1:/var/www/app \

etc/apache-bootstrap

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ OPTS_SERVICE_USER_GROUP_PASSWORD="${SERVICE_USER_GROUP_PASSWORD:-$(get_password
1919
OPTS_SERVICE_USER_PASSWORD="${SERVICE_USER_PASSWORD:-$(get_password 8)}"
2020
OPTS_SUEXECUSERGROUP="${SUEXECUSERGROUP:-false}"
2121

22-
if [[ ! -d ${OPTS_APP_HOME_DIR} ]] && [[ -d ${OPTS_APP_HOME_DIR_TEMPLATE} ]]; then
22+
if [[ ! -d ${OPTS_APP_HOME_DIR} ]] && [[ -d ${APP_HOME_DIR_TEMPLATE} ]]; then
2323
echo "Recreate the ${OPTS_APP_HOME_DIR} directory."
2424
mkdir -p ${OPTS_APP_HOME_DIR}
2525
fi
@@ -39,8 +39,27 @@ if [[ ${OPTS_APP_HOME_DIR} != /var/www/app ]]; then
3939
unlink /home/app && ln -s ${OPTS_APP_HOME_DIR} /home/app
4040
fi
4141

42+
# Server MPM
43+
HTTPD_MPM_PREFORK=/usr/sbin/httpd
44+
HTTPD_MPM_WORKER=/usr/sbin/httpd.worker
45+
HTTPD=${HTTPD:-${HTTPD_MPM_PREFORK}}
46+
if [[ ${HTTPD} == ${HTTPD_MPM_PREFORK} ]]; then
47+
echo "Apache Server MPM: Prefork"
48+
sed -i \
49+
-e "s~HTTPD=${HTTPD_MPM_WORKER}~#HTTPD=${HTTPD_MPM_WORKER}~g" \
50+
/etc/sysconfig/httpd
51+
elif [[ ${HTTPD} == ${HTTPD_MPM_WORKER} ]]; then
52+
echo "Apache Server MPM: Worker"
53+
sed -i \
54+
-e "s~#HTTPD=${HTTPD_MPM_WORKER}~HTTPD=${HTTPD_MPM_WORKER}~g" \
55+
/etc/sysconfig/httpd
56+
else
57+
echo "ERROR: Apache Server MPM (${HTTPD}) unknown."
58+
exit 1
59+
fi
60+
4261
# If users need to change the vhost.conf the SSL version can be rebuilt if it is deleted
43-
if [[ ${OPTS_APACHE_MOD_SSL_ENABLED} == "true" ]] && [[ ! -f ${OPTS_APP_HOME_DIR}/vhost-ssl.conf ]] && [[ -f ${OPTS_APP_HOME_DIR}/vhost.conf ]]; then
62+
if [[ ${OPTS_APACHE_MOD_SSL_ENABLED} == true ]] && [[ ! -f ${OPTS_APP_HOME_DIR}/vhost-ssl.conf ]] && [[ -f ${OPTS_APP_HOME_DIR}/vhost.conf ]]; then
4463
echo "Rebuilding the SSL VirtualHost configuration."
4564
cp -pf ${OPTS_APP_HOME_DIR}/vhost.conf ${OPTS_APP_HOME_DIR}/vhost-ssl.conf
4665

etc/services-config/httpd/apache-bootstrap.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ APACHE_LOAD_MODULES="${APACHE_LOAD_MODULES:-${APACHE_LOAD_MODULES_DEFAULT}}"
2121
APACHE_MOD_SSL_ENABLED="${APACHE_MOD_SSL_ENABLED:-false}"
2222
APP_HOME_DIR="${APP_HOME_DIR:-/var/www/app}"
2323
DATE_TIMEZONE="${DATE_TIMEZONE:-UTC}"
24+
HTTPD="${HTTPD:-/usr/sbin/httpd}"
2425
SERVICE_USER="${SERVICE_USER:-app}"
2526
SERVICE_USER_GROUP="${SERVICE_USER_GROUP:-app-www}"
2627
SERVICE_USER_GROUP_PASSWORD=""

etc/services-config/supervisor/supervisord.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ stdout_events_enabled = true
3333

3434
[program:httpd]
3535
priority = 100
36-
command = /bin/bash -c "/bin/sleep 2 && /usr/sbin/httpd.worker -c \"ErrorLog /dev/stdout\" -DFOREGROUND"
36+
command = /bin/bash -c "/bin/sleep 2 && %(ENV_HTTPD)s -c \"ErrorLog /dev/stdout\" -DFOREGROUND"
3737
redirect_stderr = true
3838
stdout_logfile = /var/log/httpd/error_log
3939
stdout_events_enabled = true

run.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ DOCKER_NAME=${SERVICE_UNIT_NAME}.${SERVICE_UNIT_APP_GROUP}.${SERVICE_UNIT_LOCAL_
2828

2929
VOLUME_CONFIG_NAME=volume-config.${DOCKER_NAME}
3030

31-
APACHE_MOD_SSL_ENABLED=false
31+
APACHE_MOD_SSL_ENABLED=false
32+
HTTPD=/usr/sbin/httpd.worker

run.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,6 @@ if ! have_docker_container_name ${VOLUME_CONFIG_NAME}; then
8282
if [[ -z $(find ${CONTAINER_MOUNT_PATH_CONFIG}/supervisor -maxdepth 1 -type f) ]]; then
8383
CMD=$(cp -R etc/services-config/supervisor ${CONTAINER_MOUNT_PATH_CONFIG}/)
8484
$CMD || sudo $CMD
85-
else
86-
# In case the supervisor configuration exists from the mod_php parent container
87-
if [[ $(uname) == Darwin ]]; then
88-
CMD=$(sed -i '' -e 's~/usr/sbin/httpd ~/usr/sbin/httpd.worker ~g' ${CONTAINER_MOUNT_PATH_CONFIG}/supervisor/supervisord.conf)
89-
else
90-
CMD=$(sed -i -e 's~/usr/sbin/httpd ~/usr/sbin/httpd.worker ~g' ${CONTAINER_MOUNT_PATH_CONFIG}/supervisor/supervisord.conf)
91-
fi
92-
$CMD || sudo $CMD
9385
fi
9486

9587
if [[ ! -d ${CONTAINER_MOUNT_PATH_CONFIG}/httpd ]]; then
@@ -167,6 +159,7 @@ docker run \
167159
--env "APACHE_MOD_SSL_ENABLED=false" \
168160
--env "APP_HOME_DIR=${APP_HOME_DIR}" \
169161
--env "DATE_TIMEZONE=UTC" \
162+
--env "HTTPD=${HTTPD}" \
170163
--env "SERVICE_USER=app" \
171164
--env "SERVICE_USER_GROUP=app-www" \
172165
--env "SERVICE_USER_PASSWORD=" \
@@ -196,6 +189,7 @@ docker run \
196189
# --env "APACHE_MOD_SSL_ENABLED=false" \
197190
# --env "APP_HOME_DIR=/var/www/app-1" \
198191
# --env "DATE_TIMEZONE=Europe/London" \
192+
# --env "HTTPD=/usr/sbin/httpd.worker" \
199193
# --env "SERVICE_USER=app" \
200194
# --env "SERVICE_USER_GROUP=app-www" \
201195
# --env "SERVICE_USER_PASSWORD=" \
@@ -206,6 +200,6 @@ docker run \
206200
# )
207201

208202
if is_docker_container_name_running ${DOCKER_NAME}; then
209-
docker ps | awk -v pattern="${DOCKER_NAME}$" '$NF ~ pattern { print $0 ; }'
203+
docker ps | awk -v pattern="${DOCKER_NAME}$" '$NF ~ pattern { print $0; }'
210204
echo " ---> Docker container running."
211205
fi

0 commit comments

Comments
 (0)