From 5cff390c081bdfb756a8977ad0bd56d778202d6b Mon Sep 17 00:00:00 2001 From: startxfr Date: Sat, 6 Feb 2016 05:05:57 +0100 Subject: reorg avec gestion des sig --- Applications/phpmyadmin/docker-compose.yml | 2 +- Services/apache/Dockerfile | 23 +++++------ Services/apache/README.md | 16 ++++---- Services/apache/docker-compose.yml | 4 +- Services/apache/index.html | 22 ++++------ Services/apache/run.sh | 8 +--- Services/apache/sx-httpd.sh | 66 ++++++++++++------------------ Services/couchbase/Dockerfile | 6 +-- Services/couchbase/README.md | 14 +++---- Services/couchbase/docker-compose.yml | 2 +- Services/couchbase/run.sh | 32 ++++++++++----- Services/mariadb/Dockerfile | 6 +-- Services/mariadb/README.md | 16 ++++---- Services/mariadb/docker-compose.yml | 4 +- Services/mariadb/run.sh | 45 ++++++++++++-------- Services/memcache/Dockerfile | 4 +- Services/memcache/README.md | 12 +++--- Services/memcache/docker-compose.yml | 2 +- Services/memcache/run.sh | 24 +++++++---- Services/mongo/Dockerfile | 6 +-- Services/mongo/README.md | 16 ++++---- Services/mongo/docker-compose.yml | 4 +- Services/mongo/run.sh | 34 +++++++++------ Services/nodejs/Dockerfile | 8 ++-- Services/nodejs/README.md | 16 ++++---- Services/nodejs/docker-compose.yml | 4 +- Services/nodejs/run.sh | 28 ++++++++----- Services/ooconv/Dockerfile | 4 +- Services/ooconv/README.md | 10 ++--- Services/ooconv/docker-compose.yml | 2 +- Services/ooconv/run.sh | 24 ++++++----- Services/php/Dockerfile | 10 ++--- Services/php/README.md | 16 ++++---- Services/php/docker-compose.yml | 4 +- Services/php/run.sh | 31 +------------- Services/postgres/Dockerfile | 6 +-- Services/postgres/README.md | 16 ++++---- Services/postgres/docker-compose.yml | 4 +- Services/postgres/run.sh | 48 +++++++++++++--------- 39 files changed, 298 insertions(+), 301 deletions(-) diff --git a/Applications/phpmyadmin/docker-compose.yml b/Applications/phpmyadmin/docker-compose.yml index 550cd2c..da7e84e 100644 --- a/Applications/phpmyadmin/docker-compose.yml +++ b/Applications/phpmyadmin/docker-compose.yml @@ -14,5 +14,5 @@ server: CONTAINER_INSTANCE: "application-phpmyadmin" SERVER_NAME: "localhost" volumes: - - "/tmp/container/logs/phpmyadmin:/data/logs/apache" + - "/tmp/container/logs/phpmyadmin:/logs/apache" - "/tmp/container/phpmyadmin:/data/apache" \ No newline at end of file diff --git a/Services/apache/Dockerfile b/Services/apache/Dockerfile index 9682a0a..78e7cdc 100644 --- a/Services/apache/Dockerfile +++ b/Services/apache/Dockerfile @@ -5,24 +5,21 @@ USER root RUN dnf -y install httpd && \ dnf clean all ENV HTTPDCONF=/etc/httpd/conf.d/app.conf \ - STARTUPLOG=/data/logs/apache/startup.log \ - LOG_PATH=/data/logs/apache \ - APP_PATH=/data/apache \ - TMP_APP_PATH=/tmp/apache + STARTUPLOG=/logs/startup.log \ + LOG_PATH=/logs \ + APP_PATH=/app \ + DATA_PATH=/data COPY httpd.conf $HTTPDCONF COPY *.sh /bin/ RUN chmod 775 /bin/run.sh /bin/sx-httpd.sh && \ chmod ug+r $HTTPDCONF && \ - rm -f /etc/httpd/conf.d/autoindex.conf && \ - rm -f /etc/httpd/conf.d/welcome.conf && \ - mkdir -p $TMP_APP_PATH && \ - mkdir -p $APP_PATH && \ - mkdir -p $LOG_PATH && \ + rm -f /etc/httpd/conf.d/autoindex.conf /etc/httpd/conf.d/welcome.conf && \ + mkdir -p $DATA_PATH $APP_PATH $LOG_PATH && \ touch $STARTUPLOG -COPY ./ $TMP_APP_PATH -RUN rm -f $TMP_APP_PATH/Dockerfile $TMP_APP_PATH/httpd.conf $TMP_APP_PATH/run.sh $TMP_APP_PATH/sx-httpd.sh && \ - chown -R apache:apache $TMP_APP_PATH $APP_PATH $LOG_PATH +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_PATH $LOG_PATH EXPOSE 80 443 -VOLUME [$APP_PATH,$LOG_PATH] +VOLUME [$DATA_PATH,$LOG_PATH] CMD ["/bin/run.sh"] \ No newline at end of file diff --git a/Services/apache/README.md b/Services/apache/README.md index ed737e1..c1ae1a2 100644 --- a/Services/apache/README.md +++ b/Services/apache/README.md @@ -30,8 +30,8 @@ service: CONTAINER_INSTANCE: "service-apache" SERVER_NAME: "localhost" volumes: - - "/tmp/container/logs/apache:/data/logs/apache" - - "/tmp/container/apache:/data/apache" + - "/tmp/container/logs/apache:/logs" + - "/tmp/container/apache:/data" ``` ## Docker-compose in various situations @@ -90,8 +90,8 @@ CMD ["/bin/run.sh"] | CONTAINER_SERVICE | `string` | `no` | Define the type of service or application provided | SERVER_NAME | `string` | `no` | Server name for this container. If no name localhost will be assigned | HOSTNAME | `auto` | `auto` | Container unique id automatically assigned by docker daemon at startup -| LOG_PATH | `auto` | `auto` | default set to /data/logs/apache and used as a volume mountpoint -| APP_PATH | `auto` | `auto` | default set to /data/apache and used as a volume mountpoint +| LOG_PATH | `auto` | `auto` | default set to /logs and used as a volume mountpoint +| APP_PATH | `auto` | `auto` | default set to /data and used as a volume mountpoint ## Exposed port @@ -104,8 +104,8 @@ CMD ["/bin/run.sh"] | Container directory | Description | |----------------------|--------------------------------------------------------------------------| -| /data/logs/apache | log directory used to record container and apache logs -| /data/apache | data directory served by apache. If empty will be filled with app on startup. In other case use content from mountpoint or data volumes +| /logs | log directory used to record container and apache logs +| /data | data directory served by apache. If empty will be filled with app on startup. In other case use content from mountpoint or data volumes ## Testing the service @@ -126,8 +126,8 @@ You must have a working environment with the source code of this repository. Rea 1. Jump into the container directory with `cd Services/apache` 2. Build the container using `docker build -t sv-apache .` 3. Run this container - 1. Interactively with `docker run -p 80:80 -v /data/logs/apache -it sv-apache`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) - 2. As a daemon with `docker run -p 80:80 -v /data/logs/apache -d sv-apache` + 1. Interactively with `docker run -p 80:80 -v /logs -it sv-apache`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) + 2. As a daemon with `docker run -p 80:80 -v /logs -d sv-apache` ### Build & run a container using `docker-compose` diff --git a/Services/apache/docker-compose.yml b/Services/apache/docker-compose.yml index 60e4b4f..3c23a4b 100644 --- a/Services/apache/docker-compose.yml +++ b/Services/apache/docker-compose.yml @@ -14,5 +14,5 @@ server: CONTAINER_INSTANCE: "service-apache" SERVER_NAME: "localhost" volumes: - - "/tmp/container/logs/apache:/data/logs/apache" - - "/tmp/container/apache:/data/apache" \ No newline at end of file + - "/tmp/container/logs/apache:/logs" + - "/tmp/container/apache:/data" \ No newline at end of file diff --git a/Services/apache/index.html b/Services/apache/index.html index 039c3dc..f3a9e21 100644 --- a/Services/apache/index.html +++ b/Services/apache/index.html @@ -13,14 +13,8 @@ h3 { text-shadow: 1px 1px 0px rgba(255,255,255,1); font-size: 1.5em;margin: .2em; } h4 { font-size: 1.2em; margin: .2em; } p { font-size: 1em; margin: .5em .2em; } - ul { - padding-bottom: 1em; - padding-left: 2em; - } - a { - color: white; - text-decoration: none; - } + ul { font-size: 1em; margin: .5em .2em; padding-bottom: 1em; padding-left: 2em; } + a { color: white; text-decoration: none; } body > header h1 { color: #000e44; text-shadow: 0 0 3px rgb(255,255,255), 0 0 10px rgba(255,255,255,1), 0 0 20px rgba(255,255,255,0.6); float: left } body > header h1 span { color: #0c6f5e } body > header h2 { color: white; font-size: .7em; font-weight: normal; margin: 2.2em 0 0 1em; float: left } @@ -28,8 +22,6 @@ article header { margin: 0;padding: .3em; box-shadow: 0 0 5px rgba(0,0,0,0.9); border-radius: 5px 5px 0 0; width: 892px; } article h3 { display: inline; } article > details { margin: 1em; } - - body#error { background-color : #533;} #error article { color : darkred; background-color : rgba(255,255,255,0.9); clear: both } #error article h2 { color : white; text-shadow: 0 0 2px white, 0 0 15px #600, 3px 3px 8px rgba(50,0,0,0.9); } @@ -37,7 +29,6 @@ #error h3, #error article a { color : #744; } #error article a:hover { color : #533; } #error pre.xdebug-var-dump {font-size:0.8em} - body#answer { background-color : #353 } #answer article { color : #575;background-color : rgba(255,255,255,0.9); clear: both } #answer article h2 { color : white; text-shadow: 0 0 2px rgba(11,45,11,0.9), 0 0 10px rgba(11,45,11,0.8); } @@ -57,12 +48,13 @@

You are actually running an apache webserver 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 + + + + \ No newline at end of file diff --git a/Services/apache/run.sh b/Services/apache/run.sh index ee10346..7a06314 100644 --- a/Services/apache/run.sh +++ b/Services/apache/run.sh @@ -2,12 +2,6 @@ source /bin/sx-lib.sh source /bin/sx-httpd.sh -if [[ "$0" == *"run.sh" && ! $1 = "" ]];then - eval "$@"; -fi - 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 +start_service_httpd diff --git a/Services/apache/sx-httpd.sh b/Services/apache/sx-httpd.sh index b850ee3..707b16d 100644 --- a/Services/apache/sx-httpd.sh +++ b/Services/apache/sx-httpd.sh @@ -9,11 +9,15 @@ function check_httpd_environment { echo "! WARNING : auto-assigned value : $SERVER_NAME" fi if [ ! -v APP_PATH ]; then - APP_PATH="/data/apache" + APP_PATH="/app" export APP_PATH fi + if [ ! -v DATA_PATH ]; then + DATA_PATH="/data" + export DATA_PATH + fi if [ ! -v LOG_PATH ]; then - LOG_PATH="/data/logs/apache" + LOG_PATH="/logs" export LOG_PATH fi } @@ -38,54 +42,36 @@ function display_container_httpd_header { if [ -v APP_PATH ]; then echo "| App path : $APP_PATH" fi + if [ -v DATA_PATH ]; then + echo "| Data path : $DATA_PATH" + fi if [ -v LOG_PATH ]; then echo "| Log path : $LOG_PATH" fi echo "+=====================================================" } -# Begin configuration before starting daemonized process -# and start generating host keys -function begin_config { - echo "=> BEGIN APACHE CONFIGURATION" - if [[ -d $TMP_APP_PATH ]]; then - if [ "$(ls -A $TMP_APP_PATH)" ]; then - echo "COPY application from $TMP_APP_PATH into $APP_PATH" - FILE_LIST=$(find $TMP_APP_PATH -maxdepth 1 -mindepth 1 -printf "%f\n") - for FILE in $FILE_LIST; do - echo -n "adding $APP_PATH/$FILE" - cp -r $TMP_APP_PATH/$FILE $APP_PATH/ - echo " DONE" - done - fi - fi -} - -# End configuration process just before starting daemon -function end_config { - 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 ..." +function stop_httpd_handler { killall httpd rm -rf /run/httpd/* - sleep 2 + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now STOPPED" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG + exit 143; # 128 + 15 -- SIGTERM } + # Start the httpd server as a deamon and execute it inside # the running shell -function start_daemon { - echo "=> Starting httpd daemon ..." | tee -a $STARTUPLOG - display_container_started | tee -a $STARTUPLOG - exec /usr/sbin/apachectl && tail -f $LOG_PATH/error.log +function start_service_httpd { + trap 'kill ${!}; stop_httpd_handler' SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL SIGSTOP SIGCONT + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now RUNNING" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG + rm -rf /run/httpd/* /tmp/httpd* + exec /usr/sbin/httpd -D FOREGROUND & + while true + do + tail -f /dev/null & wait ${!} + done } diff --git a/Services/couchbase/Dockerfile b/Services/couchbase/Dockerfile index 48465d3..25c9877 100644 --- a/Services/couchbase/Dockerfile +++ b/Services/couchbase/Dockerfile @@ -4,13 +4,13 @@ MAINTAINER Christophe LARUE USER root ENV CB_VERSION=4.1.0-dp \ CB_RELEASE_URL=http://packages.couchbase.com/releases/$CB_VERSION \ - CB_PACKAGE=couchbase-server-$CB_VERSION-centos7.x86_64.rpm + CB_PACKAGE=couchbase-server-$CB_VERSION-centos7.x86_64.rpm \ + STARTUPLOG=/logs/startup.log \ + LOG_PATH=/logs RUN dnf -y install python-httplib2 openssl && \ dnf clean all && \ wget $CB_RELEASE_URL/$CB_PACKAGE && \ rpm --install $CB_PACKAGE -ENV STARTUPLOG=/data/logs/couchbase/startup.log \ - LOG_PATH=/data/logs/couchbase COPY *.sh /bin/ RUN chmod 775 /bin/run.sh && \ mkdir -p $LOG_PATH && \ diff --git a/Services/couchbase/README.md b/Services/couchbase/README.md index dce4fb7..5f97eec 100644 --- a/Services/couchbase/README.md +++ b/Services/couchbase/README.md @@ -25,8 +25,8 @@ service: CONTAINER_SERVICE: "couchbase" CONTAINER_INSTANCE: "service-couchbase" volumes: - - "/tmp/container/logs/couchbase:/data/logs/couchbase" - - "/tmp/container/couchbase:/data/couchbase" + - "/tmp/container/logs/couchbase:/logs" + - "/tmp/container/couchbase:/data" ``` ## Docker-compose in various situations @@ -69,7 +69,7 @@ CMD ["/bin/run.sh"] | CONTAINER_TYPE | `string` | `no` | Container family (os, service, application. could be enhanced | CONTAINER_SERVICE | `string` | `no` | Define the type of service or application provided | HOSTNAME | `auto` | `auto` | Container unique id automatically assigned by docker daemon at startup -| LOG_PATH | `auto` | `auto` | default set to /data/logs/couchbase and used as a volume mountpoint +| LOG_PATH | `auto` | `auto` | default set to /logs and used as a volume mountpoint ## Exposed port @@ -81,8 +81,8 @@ CMD ["/bin/run.sh"] | Container directory | Description | |----------------------|--------------------------------------------------------------------------| -| /data/logs/couchbase | log directory used to record container and couchbase logs -| /data/couchbase | data directory served by couchbase. If empty will be filled with app on startup. In other case use content from mountpoint or data volumes +| /logs | log directory used to record container and couchbase logs +| /data | data directory served by couchbase. If empty will be filled with app on startup. In other case use content from mountpoint or data volumes ## Testing the service @@ -103,8 +103,8 @@ You must have a working environment with the source code of this repository. Rea 1. Jump into the container directory with `cd Services/couchbase` 2. Build the container using `docker build -t sv-couchbase .` 3. Run this container - 1. Interactively with `docker run -p 11211:11211 -v /data/logs/couchbase -it sv-couchbase`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) - 2. As a daemon with `docker run -p 11211:11211 -v /data/logs/couchbase -d sv-couchbase` + 1. Interactively with `docker run -p 11211:11211 -v /logs -it sv-couchbase`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) + 2. As a daemon with `docker run -p 11211:11211 -v /logs -d sv-couchbase` ### Build & run a container using `docker-compose` diff --git a/Services/couchbase/docker-compose.yml b/Services/couchbase/docker-compose.yml index abb01e0..309be52 100644 --- a/Services/couchbase/docker-compose.yml +++ b/Services/couchbase/docker-compose.yml @@ -12,4 +12,4 @@ server: CONTAINER_SERVICE: "couchbase" CONTAINER_INSTANCE: "service-couchbase" volumes: - - "/tmp/container/logs/couchbase:/data/logs/couchbase" \ No newline at end of file + - "/tmp/container/logs/couchbase:/logs" \ No newline at end of file diff --git a/Services/couchbase/run.sh b/Services/couchbase/run.sh index 4794ee0..2f6f655 100644 --- a/Services/couchbase/run.sh +++ b/Services/couchbase/run.sh @@ -42,22 +42,34 @@ function end_config { echo "=> END COUCHBASE CONFIGURATION" } +function stop_couchbase_handler { + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now STOPPED" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG + if [ $pid -ne 0 ]; then + kill -SIGTERM "$pid" + wait "$pid" + fi + exit 143; # 128 + 15 -- SIGTERM +} + # Start the couchbase server as a deamon and execute it inside # the running shell -function start_daemon { - echo "=> Starting couchbase daemon ..." | tee -a $STARTUPLOG - display_container_started | tee -a $STARTUPLOG +function start_service_couchbase { + trap 'kill ${!}; stop_couchbase_handler' SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL SIGSTOP SIGCONT + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now RUNNING" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG # exec couchbase -u daemon -v -exec tail -f /etc/redhat-release + exec tail -f /dev/null & + while true + do + tail -f /dev/null & wait ${!} + done } - -if [[ "$0" == *"run.sh" && ! $1 = "" ]];then - eval "$@"; -fi - check_environment | tee -a $STARTUPLOG display_container_couchbase_header | tee -a $STARTUPLOG begin_config | tee -a $STARTUPLOG end_config | tee -a $STARTUPLOG -start_daemon +start_service_couchbase diff --git a/Services/mariadb/Dockerfile b/Services/mariadb/Dockerfile index 0e6c67f..75d5150 100644 --- a/Services/mariadb/Dockerfile +++ b/Services/mariadb/Dockerfile @@ -6,9 +6,9 @@ RUN dnf -y install mariadb-common mariadb-libs mariadb-config mariadb-errmsg ma && dnf clean all && \ mkdir -p /tmp/sql ENV MY_CONF=/etc/my.cnf \ - STARTUPLOG=/data/logs/mariadb/startup.log \ - LOG_PATH=/data/logs/mariadb \ - DATA_PATH=/data/mariadb \ + STARTUPLOG=/logs/startup.log \ + LOG_PATH=/logs \ + DATA_PATH=/data \ LOADSQL_PATH=/tmp/sql COPY *.sh /bin/ COPY my.cnf $MY_CONF diff --git a/Services/mariadb/README.md b/Services/mariadb/README.md index f940414..454d004 100644 --- a/Services/mariadb/README.md +++ b/Services/mariadb/README.md @@ -35,8 +35,8 @@ service: MYSQL_PASSWORD: "pwd-test" MYSQL_DATABASE: "db_test" volumes: - - "/tmp/container/logs/mariadb:/data/logs/mariadb" - - "/tmp/container/mariadb:/data/mariadb" + - "/tmp/container/logs/mariadb:/logs" + - "/tmp/container/mariadb:/data" ``` ## Docker-compose in various situations @@ -99,8 +99,8 @@ CMD ["/bin/run.sh"] | MYSQL_DATABASE | `string` | `no` | If present, add a new database with this name | LOADSQL_PATH | `string` | `auto` | Path used to find sql dump to import at startup | HOSTNAME | `auto` | `auto` | Container unique id automatically assigned by docker daemon at startup -| LOG_PATH | `auto` | `auto` | default set to /data/logs/mariadb and used as a volume mountpoint -| DATA_PATH | `auto` | `auto` | default set to /data/mariadb and used as a volume mountpoint +| LOG_PATH | `auto` | `auto` | default set to /logs and used as a volume mountpoint +| DATA_PATH | `auto` | `auto` | default set to /data and used as a volume mountpoint ## Exposed port @@ -112,8 +112,8 @@ CMD ["/bin/run.sh"] | Container directory | Description | |----------------------|--------------------------------------------------------------------------| -| /data/logs/mariadb | log directory used to record container and mariadb logs -| /data/mariadb | data directory served by mariadb. If empty will be filled with database files on startup. In other case use content from mountpoint or data volumes +| /logs | log directory used to record container and mariadb logs +| /data | data directory served by mariadb. If empty will be filled with database files on startup. In other case use content from mountpoint or data volumes ## Testing the service @@ -134,8 +134,8 @@ You must have a working environment with the source code of this repository. Rea 1. Jump into the container directory with `cd Services/mariadb` 2. Build the container using `docker build -t sv-mariadb .` 3. Run this container - 1. Interactively with `docker run -p 3306:3306 -v /data/logs/mariadb -it sv-mariadb`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) - 2. As a daemon with `docker run -p 3306:3306 -v /data/logs/mariadb -d sv-mariadb` + 1. Interactively with `docker run -p 3306:3306 -v /logs -it sv-mariadb`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) + 2. As a daemon with `docker run -p 3306:3306 -v /logs -d sv-mariadb` ### Build & run a container using `docker-compose` diff --git a/Services/mariadb/docker-compose.yml b/Services/mariadb/docker-compose.yml index f1a39ca..18df4ad 100644 --- a/Services/mariadb/docker-compose.yml +++ b/Services/mariadb/docker-compose.yml @@ -16,5 +16,5 @@ server: MYSQL_PASSWORD: "pwd-test" MYSQL_DATABASE: "db_test" volumes: - - "/tmp/container/logs/mariadb:/data/logs/mariadb" - - "/tmp/container/mariadb:/data/mariadb" \ No newline at end of file + - "/tmp/container/logs/mariadb:/logs" + - "/tmp/container/mariadb:/data" \ No newline at end of file diff --git a/Services/mariadb/run.sh b/Services/mariadb/run.sh index c11f784..be35356 100644 --- a/Services/mariadb/run.sh +++ b/Services/mariadb/run.sh @@ -4,11 +4,11 @@ source /bin/sx-lib.sh function check_mariadb_environment { check_environment if [ ! -v DATA_PATH ]; then - DATA_PATH="/data/mariadb" + DATA_PATH="/data" export DATA_PATH fi if [ ! -v LOG_PATH ]; then - LOG_PATH="/data/logs/mariadb" + LOG_PATH="/logs" export LOG_PATH fi } @@ -80,6 +80,12 @@ function begin_config { mysql_install_db --datadir=$DATA_PATH --defaults-file=$MY_CONF --user=mysql > /dev/null 2>&1 chown mysql:mysql -R $DATA_PATH echo "Installing MariaDB in $DATA_PATH is DONE !" + config_startserver + config_createadmin + config_createuser + config_createdatabase + config_importsql + config_stopserver else echo "mariadb directory is initialized" echo "Reusing MariaDB in $DATA_PATH ..." @@ -203,27 +209,30 @@ function end_config { echo "=> END MARIADB CONFIGURATION" } +function stop_mariadb_handler { + mysqladmin -uroot shutdown + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now STOPPED" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG + exit 143; # 128 + 15 -- SIGTERM +} + # Start the mariadb server as a deamon and execute it inside # the running shell -function start_daemon { - echo "=> Starting mariadb daemon ..." | tee -a $STARTUPLOG - display_container_started | tee -a $STARTUPLOG - exec mysqld_safe +function start_service_mariadb { + trap 'kill ${!}; stop_mariadb_handler' SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL SIGSTOP SIGCONT + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now RUNNING" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG + exec mysqld_safe & + while true + do + tail -f /dev/null & wait ${!} + done } - -if [[ "$0" == *"run.sh" && ! $1 = "" ]];then - eval "$@"; -fi - check_mariadb_environment | tee -a $STARTUPLOG display_container_mariadb_header | tee -a $STARTUPLOG begin_config | tee -a $STARTUPLOG -config_startserver | tee -a $STARTUPLOG -config_createadmin | tee -a $STARTUPLOG -config_createuser | tee -a $STARTUPLOG -config_createdatabase | tee -a $STARTUPLOG -config_importsql | tee -a $STARTUPLOG -config_stopserver | tee -a $STARTUPLOG end_config | tee -a $STARTUPLOG -start_daemon +start_service_mariadb diff --git a/Services/memcache/Dockerfile b/Services/memcache/Dockerfile index 32724b2..55ae563 100644 --- a/Services/memcache/Dockerfile +++ b/Services/memcache/Dockerfile @@ -4,8 +4,8 @@ MAINTAINER Christophe LARUE USER root RUN dnf -y install memcached && \ dnf clean all -ENV STARTUPLOG=/data/logs/memcache/startup.log \ - LOG_PATH=/data/logs/memcache +ENV STARTUPLOG=/logs/startup.log \ + LOG_PATH=/logs COPY *.sh /bin/ RUN chmod 775 /bin/run.sh && \ mkdir -p $LOG_PATH && \ diff --git a/Services/memcache/README.md b/Services/memcache/README.md index 0ce3167..8f88de3 100644 --- a/Services/memcache/README.md +++ b/Services/memcache/README.md @@ -29,7 +29,7 @@ service: CONTAINER_SERVICE: "memcache" CONTAINER_INSTANCE: "service-memcache" volumes: - - "/tmp/container/logs/memcache:/data/logs/memcache" + - "/tmp/container/logs/memcache:/logs" ``` ## Docker-compose in various situations @@ -72,7 +72,7 @@ CMD ["/bin/run.sh"] | CONTAINER_TYPE | `string` | `no` | Container family (os, service, application. could be enhanced | CONTAINER_SERVICE | `string` | `no` | Define the type of service or application provided | HOSTNAME | `auto` | `auto` | Container unique id automatically assigned by docker daemon at startup -| LOG_PATH | `auto` | `auto` | default set to /data/logs/memcache and used as a volume mountpoint +| LOG_PATH | `auto` | `auto` | default set to /logs and used as a volume mountpoint ## Exposed port @@ -84,8 +84,8 @@ CMD ["/bin/run.sh"] | Container directory | Description | |----------------------|--------------------------------------------------------------------------| -| /data/logs/memcache | log directory used to record container and memcache logs -| /data/memcache | data directory served by memcache. If empty will be filled with app on startup. In other case use content from mountpoint or data volumes +| /logs | log directory used to record container and memcache logs +| /data | data directory served by memcache. If empty will be filled with app on startup. In other case use content from mountpoint or data volumes ## Testing the service @@ -106,8 +106,8 @@ You must have a working environment with the source code of this repository. Rea 1. Jump into the container directory with `cd Services/memcache` 2. Build the container using `docker build -t sv-memcache .` 3. Run this container - 1. Interactively with `docker run -p 11211:11211 -v /data/logs/memcache -it sv-memcache`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) - 2. As a daemon with `docker run -p 11211:11211 -v /data/logs/memcache -d sv-memcache` + 1. Interactively with `docker run -p 11211:11211 -v /logs -it sv-memcache`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) + 2. As a daemon with `docker run -p 11211:11211 -v /logs -d sv-memcache` ### Build & run a container using `docker-compose` diff --git a/Services/memcache/docker-compose.yml b/Services/memcache/docker-compose.yml index 8368855..ae39b41 100644 --- a/Services/memcache/docker-compose.yml +++ b/Services/memcache/docker-compose.yml @@ -12,4 +12,4 @@ server: CONTAINER_SERVICE: "memcache" CONTAINER_INSTANCE: "service-memcache" volumes: - - "/tmp/container/logs/memcache:/data/logs/memcache" \ No newline at end of file + - "/tmp/container/logs/memcache:/logs" \ No newline at end of file diff --git a/Services/memcache/run.sh b/Services/memcache/run.sh index 77ef648..3c5a8cd 100644 --- a/Services/memcache/run.sh +++ b/Services/memcache/run.sh @@ -42,21 +42,27 @@ function end_config { echo "=> END MEMCACHE CONFIGURATION" } +function stop_memcache_handler { + killall memcached + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now STOPPED" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG + exit 143; # 128 + 15 -- SIGTERM +} + + # Start the memcache server as a deamon and execute it inside # the running shell -function start_daemon { - echo "=> Starting memcache daemon ..." | tee -a $STARTUPLOG - display_container_started | tee -a $STARTUPLOG +function start_service_memcache { + trap 'kill ${!}; stop_memcache_handler' SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL SIGSTOP SIGCONT + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now RUNNING" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG exec memcached -u daemon -v } - -if [[ "$0" == *"run.sh" && ! $1 = "" ]];then - eval "$@"; -fi - check_environment | tee -a $STARTUPLOG display_container_memcache_header | tee -a $STARTUPLOG begin_config | tee -a $STARTUPLOG end_config | tee -a $STARTUPLOG -start_daemon +start_service_memcache diff --git a/Services/mongo/Dockerfile b/Services/mongo/Dockerfile index 98ec5f8..c3f1bab 100644 --- a/Services/mongo/Dockerfile +++ b/Services/mongo/Dockerfile @@ -4,9 +4,9 @@ MAINTAINER Christophe LARUE USER root RUN dnf -y install mongodb mongodb-server libmongo-client rsyslog-mongodb && \ dnf clean all -ENV STARTUPLOG=/data/logs/mongodb/startup.log \ - LOG_PATH=/data/logs/mongodb \ - DATA_PATH=/data/mongodb +ENV STARTUPLOG=/logs/startup.log \ + LOG_PATH=/logs \ + DATA_PATH=/data COPY *.sh /bin/ RUN chmod 775 /bin/run.sh && \ mkdir -p $DATA_PATH && \ diff --git a/Services/mongo/README.md b/Services/mongo/README.md index 5951629..194c2e7 100644 --- a/Services/mongo/README.md +++ b/Services/mongo/README.md @@ -29,8 +29,8 @@ service: CONTAINER_SERVICE: "mongo" CONTAINER_INSTANCE: "service-mongo" volumes: - - "/tmp/container/logs/mongo:/data/logs/mongo" - - "/tmp/container/mongo:/data/mongo" + - "/tmp/container/logs/mongo:/logs" + - "/tmp/container/mongo:/data" ``` ## Docker-compose in various situations @@ -88,8 +88,8 @@ CMD ["/bin/run.sh"] | CONTAINER_TYPE | `string` | `no` | Container family (os, service, application. could be enhanced | CONTAINER_SERVICE | `string` | `no` | Define the type of service or application provided | HOSTNAME | `auto` | `auto` | Container unique id automatically assigned by docker daemon at startup -| LOG_PATH | `auto` | `auto` | default set to /data/logs/mongo and used as a volume mountpoint -| DATA_PATH | `auto` | `auto` | default set to /data/mongo and used as a volume mountpoint +| LOG_PATH | `auto` | `auto` | default set to /logs and used as a volume mountpoint +| DATA_PATH | `auto` | `auto` | default set to /data and used as a volume mountpoint ## Exposed port @@ -101,8 +101,8 @@ CMD ["/bin/run.sh"] | Container directory | Description | |----------------------|--------------------------------------------------------------------------| -| /data/logs/mongo | log directory used to record container and mongo logs -| /data/mongo | data directory served by mongo. If empty will be filled with app on startup. In other case use content from mountpoint or data volumes +| /logs | log directory used to record container and mongo logs +| /data | data directory served by mongo. If empty will be filled with app on startup. In other case use content from mountpoint or data volumes ## Testing the service @@ -123,8 +123,8 @@ You must have a working environment with the source code of this repository. Rea 1. Jump into the container directory with `cd Services/mongo` 2. Build the container using `docker build -t sv-mongo .` 3. Run this container - 1. Interactively with `docker run -p 27017:27017 -v /data/logs/mongo -it sv-mongo`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) - 2. As a daemon with `docker run -p 27017:27017 -v /data/logs/mongo -d sv-mongo` + 1. Interactively with `docker run -p 27017:27017 -v /logs -it sv-mongo`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) + 2. As a daemon with `docker run -p 27017:27017 -v /logs -d sv-mongo` ### Build & run a container using `docker-compose` diff --git a/Services/mongo/docker-compose.yml b/Services/mongo/docker-compose.yml index 427771d..3109a53 100644 --- a/Services/mongo/docker-compose.yml +++ b/Services/mongo/docker-compose.yml @@ -13,5 +13,5 @@ server: CONTAINER_SERVICE: "mongo" CONTAINER_INSTANCE: "service-mongo" volumes: - - "/tmp/container/logs/mongodb:/data/logs/mongodb" - - "/tmp/container/mongodb:/data/mongodb" \ No newline at end of file + - "/tmp/container/logs/mongodb:/logs" + - "/tmp/container/mongodb:/data" \ No newline at end of file diff --git a/Services/mongo/run.sh b/Services/mongo/run.sh index 14e00db..e3356c9 100644 --- a/Services/mongo/run.sh +++ b/Services/mongo/run.sh @@ -4,11 +4,11 @@ source /bin/sx-lib.sh function check_mongodb_environment { check_environment if [ ! -v APP_PATH ]; then - APP_PATH="/data/mongodb" + APP_PATH="/data" export APP_PATH fi if [ ! -v LOG_PATH ]; then - LOG_PATH="/data/logs/mongodb" + LOG_PATH="/logs" export LOG_PATH fi } @@ -69,23 +69,33 @@ function end_config { echo "=> END MONGODB CONFIGURATION" } +function stop_mongo_handler { + killall mongod + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now STOPPED" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG + exit 143; # 128 + 15 -- SIGTERM +} + + # Start the mongodb server as a deamon and execute it inside # the running shell -function start_daemon { - echo "=> Starting mongodb daemon ..." | tee -a $STARTUPLOG +function start_service_mongo { + trap 'kill ${!}; stop_mongo_handler' SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL SIGSTOP SIGCONT + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now RUNNING" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG su mongodb - display_container_started | tee -a $STARTUPLOG /usr/bin/mongod --logappend --logpath $LOG_PATH/mongodb.log --dbpath $DATA_PATH --journal --fork - exec tail -f $LOG_PATH/mongodb.log + exec tail -f /dev/null & + while true + do + tail -f /dev/null & wait ${!} + done } - -if [[ "$0" == *"run.sh" && ! $1 = "" ]];then - eval "$@"; -fi - check_mongodb_environment | tee -a $STARTUPLOG display_container_mongodb_header | tee -a $STARTUPLOG begin_config | tee -a $STARTUPLOG end_config | tee -a $STARTUPLOG -start_daemon +start_service_mongo diff --git a/Services/nodejs/Dockerfile b/Services/nodejs/Dockerfile index 43969a1..74fec14 100644 --- a/Services/nodejs/Dockerfile +++ b/Services/nodejs/Dockerfile @@ -4,11 +4,11 @@ MAINTAINER Christophe LARUE USER root RUN dnf -y install nodejs npm python make gcc && \ dnf clean all -ENV STARTUPLOG=/data/logs/nodejs/startup.log \ - LOG_PATH=/data/logs/nodejs \ - APP_PATH=/data/nodejs \ +ENV STARTUPLOG=/logs/startup.log \ + LOG_PATH=/logs \ + APP_PATH=/data \ TMP_APP_PATH=/tmp/nodejs \ - APP_MAIN=/data/nodejs/app.js + APP_MAIN=/data/app.js COPY *.sh /bin/ RUN chmod 775 /bin/run.sh && \ mkdir -p $APP_PATH && \ diff --git a/Services/nodejs/README.md b/Services/nodejs/README.md index 0aae3e5..806f2d5 100644 --- a/Services/nodejs/README.md +++ b/Services/nodejs/README.md @@ -30,8 +30,8 @@ service: CONTAINER_SERVICE: "nodejs" CONTAINER_INSTANCE: "service-nodejs" volumes: - - "/tmp/container/logs/nodejs:/data/logs/nodejs" - - "/tmp/container/nodejs:/data/nodejs" + - "/tmp/container/logs/nodejs:/logs" + - "/tmp/container/nodejs:/data" ``` ## Docker-compose in various situations @@ -89,8 +89,8 @@ CMD ["/bin/run.sh"] | CONTAINER_INSTANCE | `string` | `yes` | Container name. Should be uning to get fine grained log and application reporting | CONTAINER_TYPE | `string` | `no` | Container family (os, service, application. could be enhanced | CONTAINER_SERVICE | `string` | `no` | Define the type of service or application provided -| LOG_PATH | `auto` | `auto` | default set to /data/logs/nodejs and used as a volume mountpoint -| APP_PATH | `auto` | `auto` | default set to /data/nodejs and used as a volume mountpoint +| LOG_PATH | `auto` | `auto` | default set to /logs and used as a volume mountpoint +| APP_PATH | `auto` | `auto` | default set to /data and used as a volume mountpoint | TMP_APP_PATH | `auto` | `auto` | default set to /tmp/nodejs and used to hold app content and copy to $APP_PATH on startup (if $APP_PATH is empty) ## Exposed port @@ -103,8 +103,8 @@ CMD ["/bin/run.sh"] | Container directory | Description | |----------------------|--------------------------------------------------------------------------| -| /data/logs/nodejs | log directory used to record container and nodejs logs -| /data/nodejs | data directory served by nodejs. If empty will be filled with app on startup. In other case use content from $TMP_APP_PATH directory +| /logs | log directory used to record container and nodejs logs +| /data | data directory served by nodejs. If empty will be filled with app on startup. In other case use content from $TMP_APP_PATH directory ## Testing the service @@ -125,8 +125,8 @@ You must have a working environment with the source code of this repository. Rea 1. Jump into the container directory with `cd Services/nodejs` 2. Build the container using `docker build -t sv-nodejs .` 3. Run this container - 1. Interactively with `docker run -p 8000:8000 -v /data/logs/nodejs -it sv-nodejs`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) - 2. As a daemon with `docker run -p 8000:8000 -v /data/logs/nodejs -d sv-nodejs` + 1. Interactively with `docker run -p 8000:8000 -v /logs -it sv-nodejs`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) + 2. As a daemon with `docker run -p 8000:8000 -v /logs -d sv-nodejs` ### Build & run a container using `docker-compose` diff --git a/Services/nodejs/docker-compose.yml b/Services/nodejs/docker-compose.yml index b366f76..c5dc597 100644 --- a/Services/nodejs/docker-compose.yml +++ b/Services/nodejs/docker-compose.yml @@ -12,5 +12,5 @@ server: CONTAINER_SERVICE: "nodejs" CONTAINER_INSTANCE: "service-nodejs" volumes: - - "/tmp/container/logs/nodejs:/data/logs/nodejs" - - "/tmp/container/nodejs:/data/nodejs" \ No newline at end of file + - "/tmp/container/logs/nodejs:/logs" + - "/tmp/container/nodejs:/data" \ No newline at end of file diff --git a/Services/nodejs/run.sh b/Services/nodejs/run.sh index cc94229..870958a 100644 --- a/Services/nodejs/run.sh +++ b/Services/nodejs/run.sh @@ -5,11 +5,11 @@ source /bin/sx-lib.sh function check_nodejs_environment { check_environment if [ ! -v APP_PATH ]; then - APP_PATH="/data/nodejs" + APP_PATH="/data" export APP_PATH fi if [ ! -v LOG_PATH ]; then - LOG_PATH="/data/logs/nodejs" + LOG_PATH="/logs" export LOG_PATH fi } @@ -59,20 +59,26 @@ function end_config { echo "=> END NODEJS CONFIGURATION" } +function stop_nodejs_handler { + killall node + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now STOPPED" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG + exit 143; # 128 + 15 -- SIGTERM +} + # Start the nodejs executable with application entrypoint # the running shell -function start_daemon { - echo "=> Starting nodejs daemon ..." | tee -a $STARTUPLOG - display_container_started | tee -a $STARTUPLOG - exec node $APP_MAIN +function start_service_nodejs { + trap 'kill ${!}; stop_nodejs_handler' SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL SIGSTOP SIGCONT + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now RUNNING" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG + exec node $APP_MAIN } -if [[ "$0" == *"run.sh" && ! $1 = "" ]];then - eval "$@"; -fi - check_nodejs_environment | tee -a $STARTUPLOG display_container_nodejs_header | tee -a $STARTUPLOG begin_config | tee -a $STARTUPLOG end_config | tee -a $STARTUPLOG -start_daemon +start_service_nodejs diff --git a/Services/ooconv/Dockerfile b/Services/ooconv/Dockerfile index feeed82..b50d347 100644 --- a/Services/ooconv/Dockerfile +++ b/Services/ooconv/Dockerfile @@ -4,8 +4,8 @@ MAINTAINER Christophe LARUE USER root RUN dnf -y install unoconv libreoffice-headless libreoffice-writer libreoffice-calc pdfmod ghostscript && \ dnf clean all -ENV STARTUPLOG=/data/logs/ooconv/startup.log \ - LOG_PATH=/data/logs/ooconv +ENV STARTUPLOG=/logs/startup.log \ + LOG_PATH=/logs COPY *.sh /bin/ RUN chmod 775 /bin/run.sh && \ mkdir -p $LOG_PATH && \ diff --git a/Services/ooconv/README.md b/Services/ooconv/README.md index f35b54c..ef81641 100644 --- a/Services/ooconv/README.md +++ b/Services/ooconv/README.md @@ -29,7 +29,7 @@ service: CONTAINER_SERVICE: "ooconv" CONTAINER_INSTANCE: "service-ooconv" volumes: - - "/tmp/container/logs/ooconv:/data/logs/ooconv" + - "/tmp/container/logs/ooconv:/logs" ``` ## Docker-compose in various situations @@ -72,7 +72,7 @@ CMD ["/bin/run.sh"] | CONTAINER_TYPE | `string` | `no` | Container family (os, service, application. could be enhanced | CONTAINER_SERVICE | `string` | `no` | Define the type of service or application provided | HOSTNAME | `auto` | `auto` | Container unique id automatically assigned by docker daemon at startup -| LOG_PATH | `auto` | `auto` | default set to /data/logs/ooconv and used as a volume mountpoint +| LOG_PATH | `auto` | `auto` | default set to /logs and used as a volume mountpoint ## Exposed port @@ -84,7 +84,7 @@ CMD ["/bin/run.sh"] | Container directory | Description | |----------------------|--------------------------------------------------------------------------| -| /data/logs/ooconv | log directory used to record container and ooconv logs +| /logs | log directory used to record container and ooconv logs ## Testing the service @@ -105,8 +105,8 @@ You must have a working environment with the source code of this repository. Rea 1. Jump into the container directory with `cd Services/ooconv` 2. Build the container using `docker build -t sv-ooconv .` 3. Run this container - 1. Interactively with `docker run -p 2002:2002 -v /data/logs/ooconv -it sv-ooconv`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) - 2. As a daemon with `docker run -p 2002:2002 -v /data/logs/ooconv -d sv-ooconv` + 1. Interactively with `docker run -p 2002:2002 -v /logs -it sv-ooconv`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) + 2. As a daemon with `docker run -p 2002:2002 -v /logs -d sv-ooconv` ### Build & run a container using `docker-compose` diff --git a/Services/ooconv/docker-compose.yml b/Services/ooconv/docker-compose.yml index b22e23a..bcead90 100644 --- a/Services/ooconv/docker-compose.yml +++ b/Services/ooconv/docker-compose.yml @@ -12,4 +12,4 @@ server: CONTAINER_SERVICE: "ooconv" CONTAINER_INSTANCE: "service-ooconv" volumes: - - "/tmp/container/logs/ooconv:/data/logs/ooconv" \ No newline at end of file + - "/tmp/container/logs/ooconv:/logs" \ No newline at end of file diff --git a/Services/ooconv/run.sh b/Services/ooconv/run.sh index 4ed67b7..2d8ddf6 100644 --- a/Services/ooconv/run.sh +++ b/Services/ooconv/run.sh @@ -43,24 +43,28 @@ function end_config { echo "=> END OOCONV CONFIGURATION" } +function stop_ooconv_handler { + killall unoconv soffice.bin + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now STOPPED" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG + exit 143; # 128 + 15 -- SIGTERM +} + # Start the ooconv server as a deamon and execute it inside # the running shell -function start_daemon { - echo "=> Starting ooconv daemon ..." | tee -a $STARTUPLOG - display_container_started | tee -a $STARTUPLOG +function start_service_ooconv { + trap 'kill ${!}; stop_ooconv_handler' SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL SIGSTOP SIGCONT + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now RUNNING" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG unoconv --listener -vvv | tee -a $STARTUPLOG - sleep 1 killall unoconv soffice.bin exec unoconv --listener } - -if [[ "$0" == *"run.sh" && ! $1 = "" ]];then - eval "$@"; -fi - check_environment | tee -a $STARTUPLOG display_container_ooconv_header | tee -a $STARTUPLOG begin_config | tee -a $STARTUPLOG end_config | tee -a $STARTUPLOG -start_daemon +start_service_ooconv diff --git a/Services/php/Dockerfile b/Services/php/Dockerfile index 58653a8..4abb0f8 100644 --- a/Services/php/Dockerfile +++ b/Services/php/Dockerfile @@ -13,11 +13,11 @@ COPY php.ini /etc/php.d/sx.ini COPY run.sh /bin/ RUN chmod 775 /bin/run.sh && \ chmod ug+r $HTTPDCONF -COPY ./ $TMP_APP_PATH -RUN rm -f $TMP_APP_PATH/Dockerfile $TMP_APP_PATH/httpd.conf $TMP_APP_PATH/run.sh && \ - chown -R apache:apache $TMP_APP_PATH $APP_PATH $LOG_PATH && \ - chmod ug+r -R $TMP_APP_PATH $APP_PATH +COPY ./ $APP_PATH +RUN rm -f $APP_PATH/Dockerfile $APP_PATH/httpd.conf $APP_PATH/run.sh && \ + chown -R apache:apache $DATA_PATH $APP_PATH $LOG_PATH && \ + chmod ug+r -R $DATA_PATH $APP_PATH EXPOSE 80 443 -VOLUME [$APP_PATH,$LOG_PATH] +VOLUME [$DATA_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 4e350b3..947d102 100644 --- a/Services/php/README.md +++ b/Services/php/README.md @@ -30,8 +30,8 @@ service: CONTAINER_INSTANCE: "service-php" SERVER_NAME: "localhost" volumes: - - "/tmp/container/logs/php:/data/logs/apache" - - "/tmp/container/php:/data/apache" + - "/tmp/container/logs/php:/logs" + - "/tmp/container/php:/data" ``` ## Docker-compose in various situations @@ -90,8 +90,8 @@ CMD ["/bin/run.sh"] | CONTAINER_SERVICE | `string` | `no` | Define the type of service or application provided | SERVER_NAME | `string` | `no` | Server name for this container. If no name localhost will be assigned | HOSTNAME | `auto` | `auto` | Container unique id automatically assigned by docker daemon at startup -| LOG_PATH | `auto` | `auto` | default set to /data/logs/apache and used as a volume mountpoint -| APP_PATH | `auto` | `auto` | default set to /data/apache and used as a volume mountpoint +| LOG_PATH | `auto` | `auto` | default set to /logs and used as a volume mountpoint +| APP_PATH | `auto` | `auto` | default set to /data and used as a volume mountpoint ## Exposed port @@ -104,8 +104,8 @@ CMD ["/bin/run.sh"] | Container directory | Description | |----------------------|--------------------------------------------------------------------------| -| /data/logs/apache | log directory used to record container and php logs -| /data/apache | data directory served by php. If empty will be filled with app on startup. In other case use content from mountpoint or data volumes +| /logs | log directory used to record container and php logs +| /data | data directory served by php. If empty will be filled with app on startup. In other case use content from mountpoint or data volumes ## Testing the service @@ -126,8 +126,8 @@ You must have a working environment with the source code of this repository. Rea 1. Jump into the container directory with `cd Services/php` 2. Build the container using `docker build -t sv-php .` 3. Run this container - 1. Interactively with `docker run -p 80:80 -v /data/logs/apache -it sv-php`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) - 2. As a daemon with `docker run -p 80:80 -v /data/logs/apache -d sv-php` + 1. Interactively with `docker run -p 80:80 -v /logs -it sv-php`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) + 2. As a daemon with `docker run -p 80:80 -v /logs -d sv-php` ### Build & run a container using `docker-compose` diff --git a/Services/php/docker-compose.yml b/Services/php/docker-compose.yml index fe532d9..fa3f05f 100644 --- a/Services/php/docker-compose.yml +++ b/Services/php/docker-compose.yml @@ -14,5 +14,5 @@ server: CONTAINER_INSTANCE: "service-php" SERVER_NAME: "localhost" volumes: - - "/tmp/container/logs/php:/data/logs/apache" - - "/tmp/container/php:/data/apache" \ No newline at end of file + - "/tmp/container/logs/php:/logs" + - "/tmp/container/php:/data" \ No newline at end of file diff --git a/Services/php/run.sh b/Services/php/run.sh index 1e73c2f..0935290 100644 --- a/Services/php/run.sh +++ b/Services/php/run.sh @@ -2,10 +2,6 @@ source /bin/sx-lib.sh source /bin/sx-httpd.sh -if [[ "$0" == *"run.sh" && ! $1 = "" ]];then - eval "$@"; -fi - function display_container_php_header { echo "+=====================================================" echo "| Container : $HOSTNAME" @@ -33,31 +29,6 @@ function display_container_php_header { echo "+=====================================================" } -# Begin configuration before starting daemonized process -# and start generating host keys -function begin_php_config { - echo "=> BEGIN APACHE + PHP CONFIGURATION" - if [[ -d $TMP_APP_PATH ]]; then - if [ "$(ls -A $TMP_APP_PATH)" ]; then - echo "COPY application from $TMP_APP_PATH into $APP_PATH" - FILE_LIST=$(find $TMP_APP_PATH -maxdepth 1 -mindepth 1 -printf "%f\n") - for FILE in $FILE_LIST; do - echo -n "adding $APP_PATH/$FILE" - cp -r $TMP_APP_PATH/$FILE $APP_PATH/ - echo " DONE" - done - fi - fi -} - -# End configuration process just before starting daemon -function end_php_config { - echo "=> END APACHE + PHP CONFIGURATION" - env | grep _ >> /etc/environment -} - check_httpd_environment | tee -a $STARTUPLOG display_container_php_header | tee -a $STARTUPLOG -begin_php_config | tee -a $STARTUPLOG -end_php_config | tee -a $STARTUPLOG -start_daemon +start_service_httpd diff --git a/Services/postgres/Dockerfile b/Services/postgres/Dockerfile index 701c127..9eee587 100644 --- a/Services/postgres/Dockerfile +++ b/Services/postgres/Dockerfile @@ -5,9 +5,9 @@ USER root RUN dnf -y install postgresql postgresql-libs postgresql-server \ && dnf clean all && \ mkdir -p /tmp/sql -ENV STARTUPLOG=/data/logs/postgresql/startup.log \ - LOG_PATH=/data/logs/postgresql \ - DATA_PATH=/data/postgresql \ +ENV STARTUPLOG=/logs/startup.log \ + LOG_PATH=/logs \ + DATA_PATH=/data \ LOADSQL_PATH=/tmp/sql COPY *.sh /bin/ COPY *.sql $LOADSQL_PATH/ diff --git a/Services/postgres/README.md b/Services/postgres/README.md index d801d74..47eba27 100644 --- a/Services/postgres/README.md +++ b/Services/postgres/README.md @@ -35,8 +35,8 @@ service: POSTGRESQL_PASSWORD: "pwd-test" POSTGRESQL_DATABASE: "db_test" volumes: - - "/tmp/container/logs/postgres:/data/logs/postgres" - - "/tmp/container/postgres:/data/postgres" + - "/tmp/container/logs/postgres:/logs" + - "/tmp/container/postgres:/data" ``` ## Docker-compose in various situations @@ -99,8 +99,8 @@ CMD ["/bin/run.sh"] | POSTGRESQL_DATABASE | `string` | `no` | If present, add a new database with this name | LOADSQL_PATH | `string` | `auto` | Path used to find sql dump to import at startup | HOSTNAME | `auto` | `auto` | Container unique id automatically assigned by docker daemon at startup -| LOG_PATH | `auto` | `auto` | default set to /data/logs/postgres and used as a volume mountpoint -| DATA_PATH | `auto` | `auto` | default set to /data/postgres and used as a volume mountpoint +| LOG_PATH | `auto` | `auto` | default set to /logs and used as a volume mountpoint +| DATA_PATH | `auto` | `auto` | default set to /data and used as a volume mountpoint ## Exposed port @@ -112,8 +112,8 @@ CMD ["/bin/run.sh"] | Container directory | Description | |----------------------|--------------------------------------------------------------------------| -| /data/logs/postgres | log directory used to record container and postgres logs -| /data/postgres | data directory served by postgres. If empty will be filled with database files on startup. In other case use content from mountpoint or data volumes +| /logs | log directory used to record container and postgres logs +| /data | data directory served by postgres. If empty will be filled with database files on startup. In other case use content from mountpoint or data volumes ## Testing the service @@ -134,8 +134,8 @@ You must have a working environment with the source code of this repository. Rea 1. Jump into the container directory with `cd Services/postgres` 2. Build the container using `docker build -t sv-postgres .` 3. Run this container - 1. Interactively with `docker run -p 5432:5432 -v /data/logs/postgres -it sv-postgres`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) - 2. As a daemon with `docker run -p 5432:5432 -v /data/logs/postgres -d sv-postgres` + 1. Interactively with `docker run -p 5432:5432 -v /logs -it sv-postgres`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...) + 2. As a daemon with `docker run -p 5432:5432 -v /logs -d sv-postgres` ### Build & run a container using `docker-compose` diff --git a/Services/postgres/docker-compose.yml b/Services/postgres/docker-compose.yml index 5dd37c9..d16ed2a 100644 --- a/Services/postgres/docker-compose.yml +++ b/Services/postgres/docker-compose.yml @@ -16,5 +16,5 @@ server: POSTGRESQL_PASSWORD: "pwd-test" POSTGRESQL_DATABASE: "db_test" volumes: - - "/tmp/container/logs/postgresql:/data/logs/postgresql" - - "/tmp/container/postgresql:/data/postgresql" \ No newline at end of file + - "/tmp/container/logs/postgresql:/logs" + - "/tmp/container/postgresql:/data" \ No newline at end of file diff --git a/Services/postgres/run.sh b/Services/postgres/run.sh index 1c5436d..baea45c 100644 --- a/Services/postgres/run.sh +++ b/Services/postgres/run.sh @@ -13,11 +13,11 @@ set_listen_addresses() { function check_postgresql_environment { check_environment if [ ! -v DATA_PATH ]; then - DATA_PATH="/data/postgresql" + DATA_PATH="/data" export DATA_PATH fi if [ ! -v LOG_PATH ]; then - LOG_PATH="/data/logs/postgresql" + LOG_PATH="/logs" export LOG_PATH fi } @@ -92,6 +92,12 @@ function begin_config { echo "Installing PostgreSQL in $DATA_PATH is DONE !" chown root:postgres $STARTUPLOG chmod ug+w $STARTUPLOG + config_startserver + config_createadmin + config_createuser + config_createdatabase + config_importsql + config_stopserver fi } @@ -203,29 +209,33 @@ function end_config { echo "=> END POSTGRESQL CONFIGURATION" } +function stop_postgres_handler { + su - postgres -c "pg_ctl -D $DATA_PATH -m fast -w stop" + set_listen_addresses '*' + sleep 2 + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now STOPPED" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG + exit 143; # 128 + 15 -- SIGTERM +} + # Start the postgresql server as a deamon and execute it inside # the running shell -function start_daemon { - echo "=> Starting postgresql daemon ..." | tee -a $STARTUPLOG - display_container_started | tee -a $STARTUPLOG - su - postgres -c "pg_ctl -D $DATA_PATH -w start " - echo "postgres daemon is started" > /tmp/started - exec tail -f /tmp/started +function start_service_postgres { + trap 'kill ${!}; stop_postgres_handler' SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL SIGSTOP SIGCONT + echo "+=====================================================" | tee -a $STARTUPLOG + echo "| Container $HOSTNAME is now RUNNING" | tee -a $STARTUPLOG + echo "+=====================================================" | tee -a $STARTUPLOG + su - postgres -c "pg_ctl -D $DATA_PATH -w start " & + while true + do + tail -f /dev/null & wait ${!} + done } -if [[ "$0" == *"run.sh" && ! $1 = "" ]];then - eval "$@"; -fi - check_postgresql_environment | tee -a $STARTUPLOG display_container_postgresql_header | tee -a $STARTUPLOG begin_config | tee -a $STARTUPLOG -config_startserver | tee -a $STARTUPLOG -config_createadmin | tee -a $STARTUPLOG -config_createuser | tee -a $STARTUPLOG -config_createdatabase | tee -a $STARTUPLOG -config_importsql | tee -a $STARTUPLOG -config_stopserver | tee -a $STARTUPLOG end_config | tee -a $STARTUPLOG -start_daemon +start_service_postgres -- cgit v1.2.3