diff options
author | startxfr <clarue@startx.fr> | 2015-11-29 04:45:26 +0100 |
---|---|---|
committer | startxfr <clarue@startx.fr> | 2015-11-29 04:45:26 +0100 |
commit | eb3d88b10a0feb302a9fd1ec60a7a92caebb856c (patch) | |
tree | d5505c96ddd69b6c47cd00bb77f8de0b15012720 | |
parent | 78d1d5017e8acbc8b4bb7f0f567d10f0e47a75df (diff) | |
download | phpmyadmin-eb3d88b10a0feb302a9fd1ec60a7a92caebb856c.tar.gz phpmyadmin-eb3d88b10a0feb302a9fd1ec60a7a92caebb856c.tar.bz2 phpmyadmin-eb3d88b10a0feb302a9fd1ec60a7a92caebb856c.tar.xz phpmyadmin-eb3d88b10a0feb302a9fd1ec60a7a92caebb856c.zip |
start reshaping nodejs service
-rw-r--r-- | Services/apache/sx-httpd.sh | 2 | ||||
-rw-r--r-- | Services/nodejs/Dockerfile | 27 | ||||
-rw-r--r-- | Services/nodejs/app.js (renamed from Services/nodejs/app/app.js) | 2 | ||||
-rw-r--r-- | Services/nodejs/docker-compose.yml | 15 | ||||
-rw-r--r-- | Services/nodejs/run.sh | 67 | ||||
-rw-r--r-- | Services/nodejs/sx/nodejs.sh | 40 | ||||
-rw-r--r-- | Services/nodejs/sx/nodejs_run.sh | 7 | ||||
-rw-r--r-- | docker-compose.yml | 8 |
8 files changed, 106 insertions, 62 deletions
diff --git a/Services/apache/sx-httpd.sh b/Services/apache/sx-httpd.sh index b7d368a..a74e766 100644 --- a/Services/apache/sx-httpd.sh +++ b/Services/apache/sx-httpd.sh @@ -36,7 +36,7 @@ function display_container_httpd_header { if [ -v CONTAINER_SERVICE ]; then echo "| Service : $CONTAINER_SERVICE" fi - if [ -v CONTAINER_SERVICE ]; then + if [ -v SERVER_NAME ]; then echo "| ServerName : $SERVER_NAME" fi if [ -v APP_PATH ]; then diff --git a/Services/nodejs/Dockerfile b/Services/nodejs/Dockerfile index dc20d72..2113c64 100644 --- a/Services/nodejs/Dockerfile +++ b/Services/nodejs/Dockerfile @@ -1,12 +1,21 @@ FROM startx/fedora MAINTAINER Christophe LARUE <dev@startx.fr> -RUN dnf -y install nodejs npm python make gcc \ - && dnf clean all \ - && mkdir -p /app \ - && chmod ug+rx /app -VOLUME ["/app"] -WORKDIR /app -COPY app /app -ENV MAIN_APP /app/app.js -ENV NODE_PATH /app/node_modules +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 \ + APP_MAIN=/data/nodejs/app.js +COPY *.sh /bin/ +RUN chmod 775 /bin/run.sh && \ + mkdir -p $APP_PATH && \ + mkdir -p $LOG_PATH && \ + touch $STARTUPLOG +COPY ./ $APP_PATH +RUN rm -f $APP_PATH/Dockerfile $APP_PATH/README.md $APP_PATH/run.sh $APP_PATH/docker-compose.yml + +EXPOSE 8000 +VOLUME [$APP_PATH,$LOG_PATH] +CMD ["/bin/run.sh"]
\ No newline at end of file diff --git a/Services/nodejs/app/app.js b/Services/nodejs/app.js index aebd6b8..6a0da10 100644 --- a/Services/nodejs/app/app.js +++ b/Services/nodejs/app.js @@ -7,4 +7,4 @@ var server = http.createServer(function (request, response) { }); server.listen(8000); -console.log("Server running at http://127.0.0.1:8000/");
\ No newline at end of file +console.log("Server is running");
\ No newline at end of file diff --git a/Services/nodejs/docker-compose.yml b/Services/nodejs/docker-compose.yml new file mode 100644 index 0000000..4f26e53 --- /dev/null +++ b/Services/nodejs/docker-compose.yml @@ -0,0 +1,15 @@ +server: + build: ./ +# image: sv-nodejs + container_name: "nodejs-server" + mem_limit: 1g + memswap_limit: 1g + cpu_shares: 5 + restart: "on-failure:2" + environment: + CONTAINER_TYPE: "service" + 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 diff --git a/Services/nodejs/run.sh b/Services/nodejs/run.sh new file mode 100644 index 0000000..f10bbd2 --- /dev/null +++ b/Services/nodejs/run.sh @@ -0,0 +1,67 @@ +#!/bin/bash +source /bin/sx-lib.sh + + +function check_nodejs_environment { + check_environment + if [ ! -v APP_PATH ]; then + APP_PATH="/data/nodejs" + export APP_PATH + fi + if [ ! -v LOG_PATH ]; then + LOG_PATH="/data/logs/nodejs" + export LOG_PATH + fi +} + +function display_container_nodejs_header { + echo "+=====================================================" + echo "| Container : $HOSTNAME" + echo "| OS : $(</etc/redhat-release)" + echo "| Engine : $(node -v | head -1)" + if [ -v CONTAINER_TYPE ]; then + echo "| Type : $CONTAINER_TYPE" + fi + if [ -v CONTAINER_INSTANCE ]; then + echo "| Instance : $CONTAINER_INSTANCE" + fi + if [ -v CONTAINER_SERVICE ]; then + echo "| Service : $CONTAINER_SERVICE" + fi + if [ -v APP_PATH ]; then + echo "| App path : $APP_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 NODEJS CONFIGURATION" +} + +# End configuration process just before starting daemon +function end_config { + echo "=> END NODEJS CONFIGURATION" +} + +# Start the nodejs executable with application entrypoint +# the running shell +function start_daemon { + echo "=> Starting nodejs daemon ..." + display_container_started + 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 | tee -a $STARTUPLOG diff --git a/Services/nodejs/sx/nodejs.sh b/Services/nodejs/sx/nodejs.sh deleted file mode 100644 index fcf3ebb..0000000 --- a/Services/nodejs/sx/nodejs.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -export TERM=dumb - -# Begin configuration before starting daemonized process -# and start generating host keys -function begin_config { - echo "=> Begin nodejs configuration for host $HOSTNAME" -} - -# End configuration process just before starting daemon -function end_config { - echo "=> End nodejs configuration ..." -} - -# Start the nodejs server in background. Used to perform config -# against the database structure such as user creation -function start_server { - echo "===> Starting nodejs server ..." - node $MAIN_APP & - sleep 4 -} - -# Stop the nodejs server running in background. -function stop_server { - echo "===> Stopping nodejs server ..." - killall node - sleep 4 -} - -# Start the nodejs server as a deamon and execute it inside -# the running shell -function start_daemon { - echo "=> Starting nodejs daemon ..." - exec node $MAIN_APP -} - - -if [[ "$0" == *"nodejs.sh" && ! $1 = "" ]];then - eval "$@"; -fi
\ No newline at end of file diff --git a/Services/nodejs/sx/nodejs_run.sh b/Services/nodejs/sx/nodejs_run.sh deleted file mode 100644 index 875dea2..0000000 --- a/Services/nodejs/sx/nodejs_run.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -source /sx/nodejs.sh - -begin_config -end_config - -start_daemon
\ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index be63b68..eb23458 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,11 +27,11 @@ memcache: # extends: # file: Services/mongo/docker-compose.yml # service: server - + #nodejs: -# build: Services/nodejs/ -# container_name: "startx-sv-nodejs" -# command: node /app/app.js +# extends: +# file: Services/nodejs/docker-compose.yml +# service: server #ooconv: # build: Services/ooconv/ |