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 --- Services/couchbase/Dockerfile | 6 +++--- Services/couchbase/README.md | 14 +++++++------- Services/couchbase/docker-compose.yml | 2 +- Services/couchbase/run.sh | 32 ++++++++++++++++++++++---------- 4 files changed, 33 insertions(+), 21 deletions(-) (limited to 'Services/couchbase') 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 -- cgit v1.2.3