From 348568c89ae1ad19270e930c02a1492bc43e99b1 Mon Sep 17 00:00:00 2001
From: startxfr <clarue@startx.fr>
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 +++++++++++++++++++---------------
 Services/mariadb/Dockerfile         | 30 +++++++++++++++++-------------
 Services/mariadb/README.md          |  2 +-
 Services/mariadb/docker-compose.yml | 15 +++++++++++++++
 Services/mariadb/run.sh             | 15 +++++++++++++++
 Services/mariadb/sx/mariadb.sh      |  2 +-
 Services/php/Dockerfile             | 16 +++++++++-------
 Services/php/README.md              |  2 +-
 Services/php/docker-compose.yml     | 16 +++++++++-------
 Services/php/httpd.conf             | 10 ++++++----
 Services/php/run.sh                 | 16 +++++++---------
 15 files changed, 135 insertions(+), 88 deletions(-)
 create mode 100644 Services/mariadb/docker-compose.yml
 create mode 100644 Services/mariadb/run.sh

(limited to 'Services')

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 <dev@startx.fr>
 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
 <IfModule log_config_module>
-    CustomLog "/data/logs/httpd_access.log" combined
+    CustomLog ${LOG_PATH}/access.log combined
 </IfModule>
 
-Alias / /data/www
-<Directory "/data/www">
+Alias / ${APP_PATH}
+<Directory ${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          : $(</etc/redhat-release)"
     if [ -v CONTAINER_TYPE ]; then
         echo "| Type        : $CONTAINER_TYPE"
     fi
@@ -30,6 +37,12 @@ function display_container_httpd_header {
     if [ -v CONTAINER_SERVICE ]; then
         echo "| ServerName  : $SERVER_NAME"
     fi
+    if [ -v APP_PATH ]; then
+        echo "| App path    : $APP_PATH"
+    fi
+    if [ -v LOG_PATH ]; then
+        echo "| Log path    : $LOG_PATH"
+    fi
     echo "+====================================================="
 }
 
@@ -37,20 +50,10 @@ function display_container_httpd_header {
 # and start generating host keys
 function begin_config {
     echo "=> 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
 }
diff --git a/Services/mariadb/Dockerfile b/Services/mariadb/Dockerfile
index 5efa265..047cdda 100644
--- a/Services/mariadb/Dockerfile
+++ b/Services/mariadb/Dockerfile
@@ -1,25 +1,29 @@
 FROM startx/fedora
 MAINTAINER Christophe LARUE <dev@startx.fr>
 
+USER root
 RUN dnf -y install  mariadb-common mariadb-libs mariadb-config mariadb-errmsg mariadb-server mariadb \
     && dnf clean all \
-    && mkdir -p /var/log/mysql \
-    && touch /var/log/mysql/.keep /var/lib/mysql/.keep \
-    && chown -R mysql:mysql /var/log/mysql /var/lib/mysql \
+    && mkdir -p /var/logs/mariadb \
+    && touch /var/logs/mariadb/.keep /var/lib/mariadb/.keep \
+    && chown -R mariadb:mariadb /var/logs/mariadb /var/lib/mariadb \
     && mkdir -p /tmp/sql 
-COPY sx/* /sx/
+ENV STARTUPLOG=/data/logs/mariadb/startup.log
+COPY *.sh /bin/
 COPY *.sql /tmp/sql/
+RUN chmod 775 /bin/run.sh && \
+    mkdir /data && \
+    mkdir /data/mariadb && \
+    mkdir /data/logs && \
+    mkdir /data/logs/mariadb && \
+    touch $STARTUPLOG
+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
 RUN chmod ug+rx /sx/mariadb* /tmp/sql \
     && chown -R mysql:mysql /sx/mariadb* /tmp/sql
 
 EXPOSE 3306
-VOLUME ["/var/lib/mysql", "/var/log/mysql"]
+VOLUME ["/data/mariadb", "/var/logs/mariadb"]
 
-USER mysql
-# if you wan't to set root password, otherwise auto-generated
-# see docker logs <containerId>
-ENV mysql_newadminpwd newRootPassword
-
-
-#ENDPOINT ["/sx/mariadb_run.sh"]
-CMD ["/sx/mariadb_run.sh"]
\ No newline at end of file
+CMD ["/sx/run.sh"]
\ No newline at end of file
diff --git a/Services/mariadb/README.md b/Services/mariadb/README.md
index 0636335..b5f3d78 100644
--- a/Services/mariadb/README.md
+++ b/Services/mariadb/README.md
@@ -6,7 +6,7 @@ Container running mysqld daemon under a fedora server
 
 	docker run -d -p 3306:3306 --name="mariadb" startx/sv-mariadb
         # when used with a volume container (run data container, then run service)
-	docker run -d -v /var/lib/mysql -v /var/log/mysql --name mariadb-data startx/sv-mariadb  echo "Data container for mariadb"
+	docker run -d -v /var/lib/mysql -v /var/logs/mysql --name mariadb-data startx/sv-mariadb  echo "Data container for mariadb"
 	docker run -d -p 3306:3306 --volumes-from mariadb-data --name="mariadb" startx/sv-mariadb
 	# when used in a linked container
 	docker run -d --name="mariadb" startx/sv-mariadb
diff --git a/Services/mariadb/docker-compose.yml b/Services/mariadb/docker-compose.yml
new file mode 100644
index 0000000..62ae6b8
--- /dev/null
+++ b/Services/mariadb/docker-compose.yml
@@ -0,0 +1,15 @@
+mariadb:
+  build: ./
+#  image: sx-mariadb
+  container_name: "sx-mariadb"
+  mem_limit: 1g
+  memswap_limit: 2g
+  cpu_shares: 2
+  restart: "on-failure:2"
+  environment:
+    CONTAINER_TYPE: "service"
+    CONTAINER_SERVICE: "mariadb"
+    CONTAINER_INSTANCE: "sx-mariadb"
+  volumes:
+    - "/tmp/container/logs:/data/logs"
+    - "/tmp/container/mariadb:/data/mariadb"
\ No newline at end of file
diff --git a/Services/mariadb/run.sh b/Services/mariadb/run.sh
new file mode 100644
index 0000000..a59a9af
--- /dev/null
+++ b/Services/mariadb/run.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+source /bin/sx-lib.sh
+source /bin/sx-httpd.sh
+
+if [[ "$0" == *"run.sh" && ! $1 = "" ]];then
+    eval "$@"; 
+fi
+
+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
+display_container_started | tee -a $STARTUPLOG
+start_daemon | tee -a $STARTUPLOG
diff --git a/Services/mariadb/sx/mariadb.sh b/Services/mariadb/sx/mariadb.sh
index 5b2857d..7ff208e 100644
--- a/Services/mariadb/sx/mariadb.sh
+++ b/Services/mariadb/sx/mariadb.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 
 export TERM=dumb
-export logfile="/var/log/mysql/mysqld.log"
+export logfile="/var/logs/mysql/mysqld.log"
 
 # Begin configuration before starting daemonized process
 # redirect mysql.log to /dev/stderr
diff --git a/Services/php/Dockerfile b/Services/php/Dockerfile
index b46f098..8bb0304 100644
--- a/Services/php/Dockerfile
+++ b/Services/php/Dockerfile
@@ -8,17 +8,19 @@ RUN dnf -y install php php-pecl-mongo php-cli php-pear \
         php-bcmath php-pecl-zip php-php-gettext php-tcpdf \
         php-tcpdf-dejavu-sans-fonts php-tidy \
     && dnf clean all  
-COPY httpd.conf /etc/httpd/conf.d/app.conf
+ENV LOG_PATH=/data/logs/httpd_php  \
+    APP_PATH=/data/httpd_php
+COPY httpd.conf $HTTPDCONF
 COPY php.ini /etc/php.d/sx.ini
 COPY run.sh /bin/
 RUN chmod 775 /bin/run.sh && \
-    chmod ug+r /etc/httpd/conf.d/app.conf
-COPY ./ /data/www
-RUN rm -f /data/www/Dockerfile /data/www/httpd.conf /data/www/run.sh && \
-    chown -R apache:apache /data/www /data/logs && \
-    chmod ug+r -R /data/www
+    chmod ug+r $HTTPDCONF
+COPY ./ $APP_PATH
+RUN rm -f $APP_PATH/Dockerfile $APP_PATH/httpd.conf $APP_PATH/run.sh && \
+    chown -R apache:apache $APP_PATH $LOG_PATH && \
+    chmod ug+r -R $APP_PATH
 
 EXPOSE 80
 EXPOSE 443
-VOLUME ["/data/www","/data/logs"]
+VOLUME [$APP_PATH,$LOG_PATH]
 CMD ["/bin/run.sh"]
\ No newline at end of file
diff --git a/Services/php/README.md b/Services/php/README.md
index 2757a6a..370a3a8 100644
--- a/Services/php/README.md
+++ b/Services/php/README.md
@@ -6,7 +6,7 @@ Container running apache + php daemon under a fedora server
 
 	docker run -d -p 80:80 --name="php" startx/sv-php
         # when used with a volume container (run data container, then run service)
-	docker run -d -v /var/www/html -v /var/log/httpd --name php-data startx/sv-php  echo "Data container for php webserver"
+	docker run -d -v /var/www/html -v /var/logs/httpd --name php-data startx/sv-php  echo "Data container for php webserver"
 	docker run -d -p 80:80 --volumes-from php-data --name="php" startx/sv-php
 	when linked to another container
 	docker run -d --name="mongo" startx/sv-mongo
diff --git a/Services/php/docker-compose.yml b/Services/php/docker-compose.yml
index b8130ef..2f410ce 100644
--- a/Services/php/docker-compose.yml
+++ b/Services/php/docker-compose.yml
@@ -1,15 +1,17 @@
-apache:
+httpd_php:
   build: ./
-#  image: sx-apache
-  container_name: "sx-apache"
+#  image: sx-httpd_php
+  container_name: "sx-httpd_php"
   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_php"
+    CONTAINER_INSTANCE: "sx-httpd_php"
+    SERVER_NAME: "localhost"
+    DOC_ROOT: "/data/httpd_php"
   volumes:
-    - "/tmp/container/logs:/data/logs"
-    - "/tmp/container/www:/data/www"
\ No newline at end of file
+    - "/tmp/container/logs/httpd_php:/data/logs/httpd_php"
+    - "/tmp/container/httpd_php:/data/httpd_php"
\ No newline at end of file
diff --git a/Services/php/httpd.conf b/Services/php/httpd.conf
index 3a51a63..1ce768f 100644
--- a/Services/php/httpd.conf
+++ b/Services/php/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
 <IfModule log_config_module>
-    CustomLog "/data/logs/httpd_access.log" combined
+    CustomLog ${LOG_PATH}/access.log combined
 </IfModule>
 
-Alias / /data/www
-<Directory "/data/www">
+Alias / ${APP_PATH}
+<Directory ${APP_PATH}>
     AddDefaultCharset UTF-8
     AllowOverride All
     Order Allow,Deny
diff --git a/Services/php/run.sh b/Services/php/run.sh
index a02537e..a59a9af 100644
--- a/Services/php/run.sh
+++ b/Services/php/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,10 @@ 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
+display_container_started | tee -a $STARTUPLOG
+start_daemon | tee -a $STARTUPLOG
-- 
cgit v1.2.3