From 75a9fce47c7b77b3aa4a52768f8472e95a155aeb Mon Sep 17 00:00:00 2001 From: "R. Richard" Date: Thu, 15 Aug 2019 17:03:15 +0200 Subject: [PATCH] Modify resources' directory structure --- Dockerfile | 14 +++++--------- supervisor/components/tfw_init.conf | 6 ++++++ supervisor/tfw_init.sh | 13 +++++++++++++ supervisor/tfw_server.py | 11 ++--------- tfw/main/__init__.py | 3 ++- tfw/main/logging.py | 12 ++++++++++++ 6 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 supervisor/components/tfw_init.conf create mode 100644 supervisor/tfw_init.sh create mode 100644 tfw/main/logging.py diff --git a/Dockerfile b/Dockerfile index 5df5cf4..b3bd3b3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,16 +39,14 @@ ENV PYTHONPATH="/usr/local/lib" \ TFW_FRONTEND_DIR="/srv/frontend" \ TFW_DIR="/.tfw" \ TFW_SERVER_DIR="/.tfw/tfw_server" \ - TFW_SNAPSHOTS_DIR="/.tfw/snapshots" \ TFW_AUTH_KEY="/tmp/tfw-auth.key" \ + TFW_LOGS_DIR="/var/log/tfw" \ + TFW_PIPES_DIR="/run/tfw" \ + TFW_SNAPSHOTS_DIR="/tmp/tfw-snapshots" \ TFW_HISTFILE="/home/${AVATAO_USER}/.bash_history" \ - TFW_LOGFILE="/var/log/tfw.log" \ PROMPT_COMMAND="history -a" -COPY bashrc /tmp -RUN echo "export HISTFILE=${TFW_HISTFILE}" >> /tmp/bashrc &&\ - cat /tmp/bashrc >> /home/${AVATAO_USER}/.bashrc - +COPY bashrc supervisor/tfw_init.sh /tmp/ COPY supervisor/supervisord.conf ${TFW_SUPERVISORD_CONF} COPY supervisor/components/ ${TFW_SUPERVISORD_COMPONENTS} COPY nginx/nginx.conf ${TFW_NGINX_CONF} @@ -57,9 +55,7 @@ COPY nginx/components/ ${TFW_NGINX_COMPONENTS} COPY tfw ${TFW_LIB_DIR}/tfw COPY supervisor/tfw_server.py ${TFW_SERVER_DIR}/ -RUN for dir in "${TFW_LIB_DIR}"/tfw "/etc/nginx" "/etc/supervisor"; do \ - chown -R root:root "$dir" && chmod -R 700 "$dir"; \ - done +VOLUME ["${TFW_LOGS_DIR}", "${TFW_PIPES_DIR}"] ONBUILD ARG BUILD_CONTEXT="solvable" ONBUILD ARG NOFRONTEND="" diff --git a/supervisor/components/tfw_init.conf b/supervisor/components/tfw_init.conf new file mode 100644 index 0000000..51f65b5 --- /dev/null +++ b/supervisor/components/tfw_init.conf @@ -0,0 +1,6 @@ +[program:tfw_init] +user=root +directory=/tmp +command=bash tfw_init.sh +autorestart=false +startsecs=0 diff --git a/supervisor/tfw_init.sh b/supervisor/tfw_init.sh new file mode 100644 index 0000000..2006f09 --- /dev/null +++ b/supervisor/tfw_init.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -euo pipefail + +echo "export HISTFILE=\"${TFW_HISTFILE}\"" >> /tmp/bashrc && + cat /tmp/bashrc >> "/home/${AVATAO_USER}/.bashrc" + +if [[ -z "${HOTRELOAD}" ]]; then + for dir in "${TFW_LIB_DIR}/tfw" "/etc/nginx" "/etc/supervisor"; do + chown -R root:root "${dir}" && chmod -R 700 "${dir}"; + done +fi + +rm -f bashrc requirements.txt tfw_init.sh diff --git a/supervisor/tfw_server.py b/supervisor/tfw_server.py index eccd753..d3bbb5e 100644 --- a/supervisor/tfw_server.py +++ b/supervisor/tfw_server.py @@ -1,17 +1,10 @@ -from sys import stderr - from tornado.ioloop import IOLoop -from tfw.main import TFWServer, setup_signal_handlers -from tfw.config import TFWENV -from tfw.logging import Log, Logger, LogFormatter, VerboseLogFormatter +from tfw.main import TFWServer, setup_logger, setup_signal_handlers if __name__ == '__main__': - Logger([ - Log(stderr, LogFormatter(20)), - Log(TFWENV.LOGFILE, VerboseLogFormatter()) - ]).start() + setup_logger(__file__) TFWServer().listen() setup_signal_handlers() diff --git a/tfw/main/__init__.py b/tfw/main/__init__.py index 3e731f9..9dac792 100644 --- a/tfw/main/__init__.py +++ b/tfw/main/__init__.py @@ -1,4 +1,5 @@ -from .tfw_connector import TFWUplinkConnector, TFWConnector from .event_handler_factory import EventHandlerFactory +from .logging import setup_logger from .signal_handling import setup_signal_handlers +from .tfw_connector import TFWUplinkConnector, TFWConnector from .tfw_server import TFWServer diff --git a/tfw/main/logging.py b/tfw/main/logging.py new file mode 100644 index 0000000..6d7fb02 --- /dev/null +++ b/tfw/main/logging.py @@ -0,0 +1,12 @@ +from sys import stderr +from os.path import join + +from tfw.config import TFWENV +from tfw.logging import Log, Logger, LogFormatter, VerboseLogFormatter + + +def setup_logger(name): + Logger([ + Log(stderr, LogFormatter(20)), + Log(join(TFWENV.LOGS_DIR, name+'.log'), VerboseLogFormatter()) + ]).start()