From 893638a7d2f9b28af5f1a460911936bda021250b Mon Sep 17 00:00:00 2001 From: tan Date: Wed, 23 Sep 2015 16:59:48 +0530 Subject: [PATCH 1/2] mount a host folder on api containers for logging --- engine/conf/tornado.conf.tpl | 4 +++- engine/src/juliabox/api/api_container.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/engine/conf/tornado.conf.tpl b/engine/conf/tornado.conf.tpl index d25b129..93be1cb 100644 --- a/engine/conf/tornado.conf.tpl +++ b/engine/conf/tornado.conf.tpl @@ -34,7 +34,9 @@ # Maximum number of requests in queue before rejecting new requests "numapilocalmax" : 5, # Seconds to wait before force deleting a non-responding container - "expire" : 1800 + "expire" : 1800, + # Host folder where API containers can write logs. This is mounted as /home/juser/logs in the container. + "log_location" : "/jboxengine/logs/api" }, # interactive container configuration diff --git a/engine/src/juliabox/api/api_container.py b/engine/src/juliabox/api/api_container.py index c34dfc6..5640174 100644 --- a/engine/src/juliabox/api/api_container.py +++ b/engine/src/juliabox/api/api_container.py @@ -24,6 +24,8 @@ class APIContainer(BaseContainer): CPU_LIMIT = 1024 MEM_LIMIT = None EXPIRE_SECS = 0 + VOLUMES = ['/home/juser/logs'] + HOST_LOG_FOLDER = '/jboxengine/logs/api' MAX_CONTAINERS = 0 MAX_PER_API_CONTAINERS = 0 @@ -44,6 +46,7 @@ def configure(): APIContainer.MAX_CONTAINERS = JBoxCfg.get('api.numlocalmax') APIContainer.MAX_PER_API_CONTAINERS = JBoxCfg.get('api.numapilocalmax') APIContainer.EXPIRE_SECS = JBoxCfg.get('api.expire') + APIContainer.HOST_LOG_FOLDER = JBoxCfg.get('api.log_location') @staticmethod def unique_container_name(api_name): @@ -80,6 +83,13 @@ def ensure_container_available(api_name): @staticmethod def create_new(api_name): + vols = { + APIContainer.HOST_LOG_FOLDER: { + 'bind': APIContainer.VOLUMES[0], + 'ro': False + } + } + container_name = APIContainer.unique_container_name(api_name) queue = APIQueue.get_queue(api_name) env = { @@ -92,12 +102,13 @@ def create_new(api_name): if image_name is None: image_name = APIContainer.DCKR_IMAGE - hostcfg = docker.utils.create_host_config(mem_limit=APIContainer.MEM_LIMIT) + hostcfg = docker.utils.create_host_config(binds=vols, mem_limit=APIContainer.MEM_LIMIT) jsonobj = APIContainer.DCKR.create_container(image_name, detach=True, host_config=hostcfg, cpu_shares=APIContainer.CPU_LIMIT, + volumes=APIContainer.VOLUMES, environment=env, hostname='juliabox', name=container_name) From 06fb96c9d3449f1059944a4b0435e597d577c122 Mon Sep 17 00:00:00 2001 From: tan Date: Thu, 24 Sep 2015 18:28:39 +0530 Subject: [PATCH 2/2] create log folder --- container/api/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/container/api/Dockerfile b/container/api/Dockerfile index 0cd4e03..d028406 100644 --- a/container/api/Dockerfile +++ b/container/api/Dockerfile @@ -26,4 +26,7 @@ WORKDIR /home/juser RUN /opt/julia_0.4.0/bin/julia -e "try; Pkg.installed(\"JuliaWebAPI\"); catch; Pkg.clone(\"https://github.com/tanmaykm/JuliaWebAPI.jl\"); end" RUN /opt/julia_0.3.11/bin/julia -e "try; Pkg.installed(\"JuliaWebAPI\"); catch; Pkg.clone(\"https://github.com/tanmaykm/JuliaWebAPI.jl\"); end" +# create a folder for storing log files, which can be mounted to a host volume during startup +RUN mkdir -p /home/juser/logs + ENTRYPOINT ["julia", "-e", "using JuliaWebAPI; using Compat; process();"]