From 348568c89ae1ad19270e930c02a1492bc43e99b1 Mon Sep 17 00:00:00 2001 From: startxfr Date: Sat, 28 Nov 2015 19:46:13 +0100 Subject: Adding display of OS flavour at startup and improving flexibility of services with env param --- Services/apache/Dockerfile | 25 +++++++++++++++---------- Services/apache/docker-compose.yml | 15 ++++++++------- Services/apache/httpd.conf | 10 ++++++---- Services/apache/run.sh | 15 ++++++--------- Services/apache/sx-httpd.sh | 34 +++++++++++++++++++--------------- 5 files changed, 54 insertions(+), 45 deletions(-) (limited to 'Services/apache') diff --git a/Services/apache/Dockerfile b/Services/apache/Dockerfile index 72a8ee8..24dc063 100644 --- a/Services/apache/Dockerfile +++ b/Services/apache/Dockerfile @@ -4,20 +4,25 @@ MAINTAINER Christophe LARUE USER root RUN dnf -y install httpd && \ dnf clean all -COPY httpd.conf /etc/httpd/conf.d/app.conf +ENV HTTPDCONF=/etc/httpd/conf.d/app.conf \ + STARTUPLOG=/data/logs/httpd/startup.log \ + LOG_PATH=/data/logs/httpd \ + APP_PATH=/data/httpd +COPY httpd.conf $HTTPDCONF COPY *.sh /bin/ RUN chmod 775 /bin/run.sh /bin/sx-httpd.sh && \ - chmod ug+r /etc/httpd/conf.d/app.conf && \ + chmod ug+r $HTTPDCONF && \ rm -f /etc/httpd/conf.d/autoindex.conf && \ rm -f /etc/httpd/conf.d/welcome.conf && \ mkdir /data && \ - mkdir /data/www && \ - mkdir /data/logs -COPY ./ /data/www -RUN rm -f /data/www/Dockerfile /data/www/httpd.conf /data/www/run.sh /data/www/sx-httpd.sh && \ - chown -R apache:apache /data/www /data/logs + mkdir $APP_PATH && \ + mkdir /data/logs && \ + mkdir $LOG_PATH && \ + touch $STARTUPLOG +COPY ./ $APP_PATH +RUN rm -f $APP_PATH/Dockerfile $APP_PATH/httpd.conf $APP_PATH/run.sh $APP_PATH/sx-httpd.sh && \ + chown -R apache:apache $APP_PATH /data/logs -EXPOSE 80 -EXPOSE 443 -VOLUME ["/data/www","/data/logs"] +EXPOSE 80 443 +VOLUME [$APP_PATH,$LOG_PATH] CMD ["/bin/run.sh"] \ No newline at end of file diff --git a/Services/apache/docker-compose.yml b/Services/apache/docker-compose.yml index e0a016f..205a439 100644 --- a/Services/apache/docker-compose.yml +++ b/Services/apache/docker-compose.yml @@ -1,16 +1,17 @@ -apache: +httpd: build: ./ -# image: sx-apache - container_name: "sx-apache" +# image: sx-httpd + container_name: "sx-httpd" mem_limit: 1g memswap_limit: 2g cpu_shares: 2 restart: "on-failure:2" environment: CONTAINER_TYPE: "service" - CONTAINER_SERVICE: "apache" - CONTAINER_INSTANCE: "sx-apache" + CONTAINER_SERVICE: "httpd" + CONTAINER_INSTANCE: "sx-httpd" SERVER_NAME: "localhost" + DOC_ROOT: "/data/httpd" volumes: - - "/tmp/container/logs:/data/logs" - - "/tmp/container/www:/data/www" \ No newline at end of file + - "/tmp/container/logs/httpd:/data/logs/httpd" + - "/tmp/container/httpd:/data/httpd" \ No newline at end of file diff --git a/Services/apache/httpd.conf b/Services/apache/httpd.conf index 8b04449..2f9d2fc 100644 --- a/Services/apache/httpd.conf +++ b/Services/apache/httpd.conf @@ -1,15 +1,17 @@ # # This file will be copied into /etc/httpd/conf.d/app.conf and loaded when httpd start # +DocumentRoot ${DOC_ROOT} +ServerName ${SERVER_NAME} ServerAdmin cl@startx.fr -ErrorLog "/data/logs/httpd_error.log" +ErrorLog ${LOG_PATH}/error.log - CustomLog "/data/logs/httpd_access.log" combined + CustomLog ${LOG_PATH}/access.log combined -Alias / /data/www - +Alias / ${APP_PATH} + AddDefaultCharset UTF-8 AllowOverride All Order Allow,Deny diff --git a/Services/apache/run.sh b/Services/apache/run.sh index a02537e..026c618 100644 --- a/Services/apache/run.sh +++ b/Services/apache/run.sh @@ -1,6 +1,4 @@ #!/bin/bash -export HTTPDCONF=/etc/httpd/conf.d/app.conf - source /bin/sx-lib.sh source /bin/sx-httpd.sh @@ -8,10 +6,9 @@ if [[ "$0" == *"run.sh" && ! $1 = "" ]];then eval "$@"; fi -check_environment -check_httpd_environment -display_container_httpd_header -begin_config -end_config -display_container_started -start_daemon +check_environment | tee -a $STARTUPLOG +check_httpd_environment | tee -a $STARTUPLOG +display_container_httpd_header | tee -a $STARTUPLOG +begin_config | tee -a $STARTUPLOG +end_config | tee -a $STARTUPLOG +start_daemon | tee -a $STARTUPLOG diff --git a/Services/apache/sx-httpd.sh b/Services/apache/sx-httpd.sh index 6b2a417..363e74f 100644 --- a/Services/apache/sx-httpd.sh +++ b/Services/apache/sx-httpd.sh @@ -7,17 +7,24 @@ function check_httpd_environment { echo "! WARNING : environment var SERVER_NAME is missing..." echo "! WARNING : auto-assigned value : $SERVER_NAME" fi - if [ ! -v DOCROOT ]; then - DOCROOT="/data/www" - export DOCROOT - echo "! WARNING : environment var DOCROOT is missing..." - echo "! WARNING : auto-assigned value : $DOCROOT" + if [ ! -v DOC_ROOT ]; then + DOC_ROOT="/data/httpd" + export DOC_ROOT + fi + if [ ! -v APP_PATH ]; then + APP_PATH="/data/httpd" + export APP_PATH + fi + if [ ! -v LOG_PATH ]; then + LOG_PATH="/data/logs/httpd" + export LOG_PATH fi } function display_container_httpd_header { echo "+=====================================================" echo "| Container : $HOSTNAME" + echo "| OS : $( BEGIN APACHE CONFIGURATION" - mkdir -p /var/run/httpd - if [ -v DOCROOT ]; then - echo "=> Set DocumentRoot to $DOCROOT in $HTTPDCONF" - echo "DocumentRoot \"$DOCROOT\"" >> $HTTPDCONF - fi - if [ -v SERVER_NAME ]; then - echo "=> Set ServerName to $SERVER_NAME in $HTTPDCONF" - echo "ServerName \"$SERVER_NAME\"" >> $HTTPDCONF - fi } # End configuration process just before starting daemon function end_config { - stop_server echo "=> END APACHE CONFIGURATION" } @@ -74,5 +77,6 @@ function stop_server { # the running shell function start_daemon { echo "=> Starting httpd daemon ..." + display_container_started exec /usr/sbin/apachectl -D FOREGROUND } -- cgit v1.2.3