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/nodejs/run.sh | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'Services/nodejs/run.sh') 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 -- cgit v1.2.3