From 5cff390c081bdfb756a8977ad0bd56d778202d6b Mon Sep 17 00:00:00 2001
From: startxfr <clarue@startx.fr>
Date: Sat, 6 Feb 2016 05:05:57 +0100
Subject: reorg avec gestion des sig

---
 Services/couchbase/run.sh | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

(limited to 'Services/couchbase/run.sh')

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