From 4bb17b8c05c6e430293217797eef694671ec1e1b Mon Sep 17 00:00:00 2001
From: startxfr 
Date: Sat, 28 Nov 2015 15:15:52 +0100
Subject: final change in script lib for OS. Change in apache and php services
---
 OS/run.sh                       |  1 +
 OS/sx-lib.sh                    | 15 +++++++++
 Services/apache/Dockerfile      |  7 +++--
 Services/apache/httpd.conf      |  2 +-
 Services/apache/run.sh          | 50 +++--------------------------
 Services/apache/sx-httpd.sh     | 48 ++++++++++++++++++++++++++++
 Services/php/Dockerfile         | 17 +++++-----
 Services/php/app/index.php      | 70 -----------------------------------------
 Services/php/docker-compose.yml | 15 +++++++++
 Services/php/httpd.conf         | 15 +++++++--
 Services/php/index.php          | 70 +++++++++++++++++++++++++++++++++++++++++
 Services/php/run.sh             | 58 ++++++++++++++++++++++++++++++++++
 docker-compose.yml              |  8 ++---
 13 files changed, 244 insertions(+), 132 deletions(-)
 create mode 100644 Services/apache/sx-httpd.sh
 delete mode 100644 Services/php/app/index.php
 create mode 100644 Services/php/docker-compose.yml
 create mode 100644 Services/php/index.php
 create mode 100644 Services/php/run.sh
diff --git a/OS/run.sh b/OS/run.sh
index 688f1bc..e1c94c6 100644
--- a/OS/run.sh
+++ b/OS/run.sh
@@ -1,5 +1,6 @@
 #!/bin/bash
 source /bin/sx-lib.sh
 
+check_environment
 display_container_header
 display_container_started
\ No newline at end of file
diff --git a/OS/sx-lib.sh b/OS/sx-lib.sh
index 22aa84a..fd2f6b5 100644
--- a/OS/sx-lib.sh
+++ b/OS/sx-lib.sh
@@ -2,6 +2,21 @@
 
 export TERM=dumb
 
+function check_environment {
+    if [ ! -v CONTAINER_TYPE ]; then
+        echo "ERROR : environment var CONTAINER_TYPE is missing. EXIT !!!"
+        exit 1;
+    fi
+    if [ ! -v CONTAINER_INSTANCE ]; then
+        echo "ERROR : environment var CONTAINER_INSTANCE is missing. EXIT !!!"
+        exit 1;
+    fi
+    if [ ! -v CONTAINER_SERVICE ]; then
+        echo "ERROR : environment var CONTAINER_SERVICE is missing. EXIT !!!"
+        exit 1;
+    fi
+}
+
 function display_container_header {
     echo "+====================================================="
     echo "| Container : $HOSTNAME"
diff --git a/Services/apache/Dockerfile b/Services/apache/Dockerfile
index 8db1b4f..72a8ee8 100644
--- a/Services/apache/Dockerfile
+++ b/Services/apache/Dockerfile
@@ -5,8 +5,8 @@ USER root
 RUN dnf -y install httpd && \
     dnf clean all 
 COPY httpd.conf /etc/httpd/conf.d/app.conf
-COPY run.sh /bin/
-RUN chmod 775 /bin/run.sh && \
+COPY *.sh /bin/
+RUN chmod 775 /bin/run.sh /bin/sx-httpd.sh && \
     chmod ug+r /etc/httpd/conf.d/app.conf && \
     rm -f /etc/httpd/conf.d/autoindex.conf && \
     rm -f /etc/httpd/conf.d/welcome.conf && \
@@ -14,7 +14,8 @@ RUN chmod 775 /bin/run.sh && \
     mkdir /data/www && \
     mkdir /data/logs
 COPY ./ /data/www
-RUN rm -f /data/www/Dockerfile /data/www/httpd.conf /data/www/run.sh
+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
 
 EXPOSE 80
 EXPOSE 443
diff --git a/Services/apache/httpd.conf b/Services/apache/httpd.conf
index ef55e71..f612424 100644
--- a/Services/apache/httpd.conf
+++ b/Services/apache/httpd.conf
@@ -1,5 +1,5 @@
 #
-# This file will be copied into /etc/httpd/conf.d/sx.conf and loaded when httpd start
+# This file will be copied into /etc/httpd/conf.d/app.conf and loaded when httpd start
 #
 ServerAdmin cl@startx.fr
 ErrorLog "/data/logs/httpd_error.log"
diff --git a/Services/apache/run.sh b/Services/apache/run.sh
index 7e2fb8e..8cb8010 100644
--- a/Services/apache/run.sh
+++ b/Services/apache/run.sh
@@ -1,55 +1,15 @@
 #!/bin/bash
-source /bin/sx-lib.sh
 export HTTPDCONF=/etc/httpd/conf.d/app.conf
 
-# Begin configuration before starting daemonized process
-# and start generating host keys
-function begin_config {
-    echo "=> BEGIN APACHE CONFIGURATION"
-    mkdir -p /var/run/httpd
-    if [ -v DOCROOT ]; then
-        echo "=> Changing document root to $DOCROOT"
-        ${DOCROOT=/data/www}
-        echo "DocumentRoot \"$DOCROOT\"" >> $HTTPDCONF
-    fi
-}
-
-# End configuration process just before starting daemon
-function end_config {
-    stop_server
-    echo "=> END APACHE CONFIGURATION"
-}
-
-# Start the httpd server in background. Used to perform config
-# against the database structure such as user creation
-function start_server {
-    echo "=> Starting httpd server"
-    /usr/sbin/apachectl &
-    sleep 2
-}
-
-# Stop the httpd server running in background. 
-function stop_server {
-    echo "=> Stopping httpd server ..."
-    killall httpd
-    rm -rf /run/httpd/*
-    sleep 2
-}
-
-# Start the httpd server as a deamon and execute it inside 
-# the running shell
-function start_daemon {
-    echo "=> Starting httpd daemon ..."
-    exec /usr/sbin/apachectl -D FOREGROUND
-}
-
-
+source /bin/sx-lib.sh
+source /bin/sx-httpd.sh
 
-if [[ "$0" == *"httpd.sh" && ! $1 = "" ]];then
+if [[ "$0" == *"run.sh" && ! $1 = "" ]];then
     eval "$@"; 
 fi
 
-
+check_environment
+check_httpd_environment
 display_container_header
 begin_config
 end_config
diff --git a/Services/apache/sx-httpd.sh b/Services/apache/sx-httpd.sh
new file mode 100644
index 0000000..ad7b995
--- /dev/null
+++ b/Services/apache/sx-httpd.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+function check_httpd_environment {
+    if [ ! -v SERVER_NAME ]; then
+        export SERVER_NAME=$CONTAINER_NAME
+    fi
+}
+
+# Begin configuration before starting daemonized process
+# and start generating host keys
+function begin_config {
+    echo "=> BEGIN APACHE CONFIGURATION"
+    mkdir -p /var/run/httpd
+    if [ -v DOCROOT ]; then
+        echo "=> Changing document root to $DOCROOT"
+        ${DOCROOT=/data/www}
+        echo "DocumentRoot \"$DOCROOT\"" >> $HTTPDCONF
+    fi
+}
+
+# End configuration process just before starting daemon
+function end_config {
+    stop_server
+    echo "=> END APACHE CONFIGURATION"
+}
+
+# Start the httpd server in background. Used to perform config
+# against the database structure such as user creation
+function start_server {
+    echo "=> Starting httpd server"
+    /usr/sbin/apachectl &
+    sleep 2
+}
+
+# Stop the httpd server running in background. 
+function stop_server {
+    echo "=> Stopping httpd server ..."
+    killall httpd
+    rm -rf /run/httpd/*
+    sleep 2
+}
+
+# Start the httpd server as a deamon and execute it inside 
+# the running shell
+function start_daemon {
+    echo "=> Starting httpd daemon ..."
+    exec /usr/sbin/apachectl -D FOREGROUND
+}
diff --git a/Services/php/Dockerfile b/Services/php/Dockerfile
index 60985df..b46f098 100644
--- a/Services/php/Dockerfile
+++ b/Services/php/Dockerfile
@@ -8,14 +8,17 @@ 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 application content
-COPY app/* /var/www/html/
-COPY httpd.conf /etc/httpd/conf.d/sx.conf
+COPY httpd.conf /etc/httpd/conf.d/app.conf
 COPY php.ini /etc/php.d/sx.ini
-RUN chmod ug+r /var/www/html/* \
-    && chown -R apache:apache /var/www/html /var/log/httpd 
+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
 
 EXPOSE 80
 EXPOSE 443
-VOLUME ["/var/www/html", "/var/log/httpd"]
-CMD ["/sx/httpd_run.sh"]
\ No newline at end of file
+VOLUME ["/data/www","/data/logs"]
+CMD ["/bin/run.sh"]
\ No newline at end of file
diff --git a/Services/php/app/index.php b/Services/php/app/index.php
deleted file mode 100644
index 411b39b..0000000
--- a/Services/php/app/index.php
+++ /dev/null
@@ -1,70 +0,0 @@
-
-
-    
-        STARTX Webserver container
-        
-        
-    
-    
-        
-            STARTX PHP Webserver
-            Online
-        
-        
-            
-            
-                You are actually running an apache webserver + php running under the latest fedora release. For more information about this container and how to add your content instead of this message, please read the following links.
-            
-            
-        
-    
-    
-
\ No newline at end of file
diff --git a/Services/php/docker-compose.yml b/Services/php/docker-compose.yml
new file mode 100644
index 0000000..b8130ef
--- /dev/null
+++ b/Services/php/docker-compose.yml
@@ -0,0 +1,15 @@
+apache:
+  build: ./
+#  image: sx-apache
+  container_name: "sx-apache"
+  mem_limit: 1g
+  memswap_limit: 2g
+  cpu_shares: 2
+  restart: "on-failure:2"
+  environment:
+    CONTAINER_TYPE: "service"
+    CONTAINER_SERVICE: "apache"
+    CONTAINER_INSTANCE: "sx-apache"
+  volumes:
+    - "/tmp/container/logs:/data/logs"
+    - "/tmp/container/www:/data/www"
\ No newline at end of file
diff --git a/Services/php/httpd.conf b/Services/php/httpd.conf
index 2cb8301..3a51a63 100644
--- a/Services/php/httpd.conf
+++ b/Services/php/httpd.conf
@@ -1,8 +1,19 @@
 #
-# This file will be copied into /etc/httpd/conf.d/sx.conf and loaded when httpd start
+# This file will be copied into /etc/httpd/conf.d/app.conf and loaded when httpd start
 #
 ServerAdmin cl@startx.fr
-
+ErrorLog "/data/logs/httpd_error.log"
+
+
+    CustomLog "/data/logs/httpd_access.log" combined
+
+
+Alias / /data/www
+
+    AddDefaultCharset UTF-8
     AllowOverride All
+    Order Allow,Deny
+    Allow from All
+    Require all granted
     DirectoryIndex index.php index.html
 
diff --git a/Services/php/index.php b/Services/php/index.php
new file mode 100644
index 0000000..411b39b
--- /dev/null
+++ b/Services/php/index.php
@@ -0,0 +1,70 @@
+
+
+    
+        STARTX Webserver container
+        
+        
+    
+    
+        
+            STARTX PHP Webserver
+            Online
+        
+        
+            
+            
+                You are actually running an apache webserver + php running under the latest fedora release. For more information about this container and how to add your content instead of this message, please read the following links.
+            
+            
+        
+    
+    
+
\ No newline at end of file
diff --git a/Services/php/run.sh b/Services/php/run.sh
new file mode 100644
index 0000000..bcddd35
--- /dev/null
+++ b/Services/php/run.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+source /bin/sx-lib.sh
+export HTTPDCONF=/etc/httpd/conf.d/app.conf
+
+# Begin configuration before starting daemonized process
+# and start generating host keys
+function begin_config {
+    echo "=> BEGIN APACHE-PHP CONFIGURATION"
+    mkdir -p /var/run/httpd
+    if [ -v DOCROOT ]; then
+        echo "=> Changing document root to $DOCROOT"
+        ${DOCROOT=/data/www}
+        echo "DocumentRoot \"$DOCROOT\"" >> $HTTPDCONF
+    fi
+}
+
+# End configuration process just before starting daemon
+function end_config {
+    stop_server
+    echo "=> END APACHE-PHP CONFIGURATION"
+}
+
+# Start the httpd server in background. Used to perform config
+# against the database structure such as user creation
+function start_server {
+    echo "=> Starting httpd + php server"
+    /usr/sbin/apachectl &
+    sleep 2
+}
+
+# Stop the httpd server running in background. 
+function stop_server {
+    echo "=> Stopping httpd + php server ..."
+    killall httpd
+    rm -rf /run/httpd/*
+    sleep 2
+}
+
+# Start the httpd server as a deamon and execute it inside 
+# the running shell
+function start_daemon {
+    echo "=> Starting httpd + php daemon ..."
+    exec /usr/sbin/apachectl -D FOREGROUND
+}
+
+
+
+if [[ "$0" == *"run.sh" && ! $1 = "" ]];then
+    eval "$@"; 
+fi
+
+check_environment
+check_httpd_environment
+display_container_header
+begin_config
+end_config
+start_daemon
+display_container_started
diff --git a/docker-compose.yml b/docker-compose.yml
index e8cf6ff..2bf7971 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -7,6 +7,10 @@ apache:
   build: Services/apache/
   container_name: "startx-sv-apache"
 
+php:
+  build: Services/php/
+  container_name: "startx-sv-php"
+
 #mariadb:
 #  build: Services/mariadb/
 #  container_name: "startx-sv-mariadb"
@@ -28,10 +32,6 @@ apache:
 #  build: Services/ooconv/
 #  container_name: "startx-sv-ooconv"
 
-#php:
-#  build: Services/php/
-#  container_name: "startx-sv-php"
-
 #postgres:
 #  build: Services/postgres/
 #  container_name: "startx-sv-postgres"
-- 
cgit v1.2.3