summaryrefslogtreecommitdiffstats
path: root/Services/nodejs
diff options
context:
space:
mode:
Diffstat (limited to 'Services/nodejs')
-rw-r--r--Services/nodejs/Dockerfile8
-rw-r--r--Services/nodejs/README.md16
-rw-r--r--Services/nodejs/docker-compose.yml4
-rw-r--r--Services/nodejs/run.sh28
4 files changed, 31 insertions, 25 deletions
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 <dev@startx.fr>
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