diff --git a/Dockerfile.buildworker b/Dockerfile.buildworker index 9ebf47427..d0c75b096 100644 --- a/Dockerfile.buildworker +++ b/Dockerfile.buildworker @@ -38,9 +38,11 @@ ADD test test ADD conf conf RUN rm -rf /conf/stack -ADD conf/init/tutumdocker.sh /etc/service/tutumdocker/run -ADD conf/init/dockerfilebuild.sh /etc/service/dockerfilebuild/run +ADD conf/init/svlogd_config /svlogd_config +ADD conf/init/preplogsdir.sh /etc/my_init.d/ +ADD conf/init/tutumdocker /etc/service/tutumdocker +ADD conf/init/dockerfilebuild /etc/service/dockerfilebuild -VOLUME ["/var/lib/docker", "/var/lib/lxc", "/conf/stack"] +VOLUME ["/var/lib/docker", "/var/lib/lxc", "/conf/stack", "/var/log"] CMD ["/sbin/my_init"] \ No newline at end of file diff --git a/Dockerfile.web b/Dockerfile.web index f4718a99f..e4958e6e0 100644 --- a/Dockerfile.web +++ b/Dockerfile.web @@ -45,11 +45,12 @@ ADD application.py application.py ADD config.py config.py ADD initdb.py initdb.py -ADD conf/init/mklogsdir.sh /etc/my_init.d/ -ADD conf/init/gunicorn.sh /etc/service/gunicorn/run -ADD conf/init/nginx.sh /etc/service/nginx/run -ADD conf/init/diffsworker.sh /etc/service/diffsworker/run -ADD conf/init/webhookworker.sh /etc/service/webhookworker/run +ADD conf/init/svlogd_config /svlogd_config +ADD conf/init/preplogsdir.sh /etc/my_init.d/ +ADD conf/init/gunicorn /etc/service/gunicorn +ADD conf/init/nginx /etc/service/nginx +ADD conf/init/diffsworker /etc/service/diffsworker +ADD conf/init/webhookworker /etc/service/webhookworker RUN cd grunt && npm install RUN cd grunt && grunt @@ -59,7 +60,7 @@ ADD test test RUN TEST=true venv/bin/python -m unittest discover RUN rm -rf /conf/stack -VOLUME ["/conf/stack", "/mnt/logs"] +VOLUME ["/conf/stack", "/var/log"] EXPOSE 443 80 diff --git a/application.py b/application.py index e7cb11c76..32491d1f9 100644 --- a/application.py +++ b/application.py @@ -67,5 +67,5 @@ application.teardown_request(close_db) application.request_class = RequestWithId if __name__ == '__main__': - logging.config.fileConfig('conf/logging_local.conf', disable_existing_loggers=False) + logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False) application.run(port=5000, debug=True, threaded=True, host='0.0.0.0') diff --git a/conf/gunicorn_config.py b/conf/gunicorn_config.py index b86250125..4ab973927 100644 --- a/conf/gunicorn_config.py +++ b/conf/gunicorn_config.py @@ -2,6 +2,5 @@ bind = 'unix:/tmp/gunicorn.sock' workers = 8 worker_class = 'gevent' timeout = 2000 -pidfile = '/tmp/gunicorn.pid' logconfig = 'conf/logging.conf' pythonpath = '.' \ No newline at end of file diff --git a/conf/gunicorn_local.py b/conf/gunicorn_local.py index 9f93eb008..3d2a36844 100644 --- a/conf/gunicorn_local.py +++ b/conf/gunicorn_local.py @@ -3,5 +3,5 @@ workers = 2 worker_class = 'gevent' timeout = 2000 daemon = False -logconfig = 'conf/logging_local.conf' +logconfig = 'conf/logging.conf' pythonpath = '.' \ No newline at end of file diff --git a/conf/http-base.conf b/conf/http-base.conf index 32e8b3730..bfa1a85f2 100644 --- a/conf/http-base.conf +++ b/conf/http-base.conf @@ -1,20 +1,8 @@ -log_format logstash_json '{ "@timestamp": "$time_iso8601", ' - '"@fields": { ' - '"remote_addr": "$remote_addr", ' - '"remote_user": "$remote_user", ' - '"body_bytes_sent": "$body_bytes_sent", ' - '"request_time": "$request_time", ' - '"status": "$status", ' - '"request": "$request", ' - '"request_method": "$request_method", ' - '"http_referrer": "$http_referer", ' - '"http_user_agent": "$http_user_agent" } }'; - types_hash_max_size 2048; include /usr/local/nginx/conf/mime.types.default; default_type application/octet-stream; -access_log /mnt/logs/nginx.access.log logstash_json; +access_log /var/log/nginx/nginx.access.log; sendfile on; gzip on; diff --git a/conf/init/diffsworker/log/run b/conf/init/diffsworker/log/run new file mode 100755 index 000000000..066f7415a --- /dev/null +++ b/conf/init/diffsworker/log/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec svlogd /var/log/diffsworker/ \ No newline at end of file diff --git a/conf/init/diffsworker.sh b/conf/init/diffsworker/run similarity index 51% rename from conf/init/diffsworker.sh rename to conf/init/diffsworker/run index 68d3c38b4..b40a1d034 100755 --- a/conf/init/diffsworker.sh +++ b/conf/init/diffsworker/run @@ -3,6 +3,6 @@ echo 'Starting diffs worker' cd / -venv/bin/python -m workers.diffsworker --log=/mnt/logs/diffsworker.log +venv/bin/python -m workers.diffsworker echo 'Diffs worker exited' \ No newline at end of file diff --git a/conf/init/dockerfilebuild/log/run b/conf/init/dockerfilebuild/log/run new file mode 100755 index 000000000..c971f6159 --- /dev/null +++ b/conf/init/dockerfilebuild/log/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec svlogd /var/log/dockerfilebuild/ \ No newline at end of file diff --git a/conf/init/dockerfilebuild.sh b/conf/init/dockerfilebuild/run similarity index 100% rename from conf/init/dockerfilebuild.sh rename to conf/init/dockerfilebuild/run diff --git a/conf/init/gunicorn/log/run b/conf/init/gunicorn/log/run new file mode 100755 index 000000000..106d6c4f8 --- /dev/null +++ b/conf/init/gunicorn/log/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec svlogd /var/log/gunicorn/ \ No newline at end of file diff --git a/conf/init/gunicorn.sh b/conf/init/gunicorn/run similarity index 100% rename from conf/init/gunicorn.sh rename to conf/init/gunicorn/run diff --git a/conf/init/mklogsdir.sh b/conf/init/mklogsdir.sh deleted file mode 100755 index 4ca2880d0..000000000 --- a/conf/init/mklogsdir.sh +++ /dev/null @@ -1,4 +0,0 @@ -#! /bin/sh - -echo 'Creating logs directory' -mkdir -p /mnt/logs \ No newline at end of file diff --git a/conf/init/nginx/log/run b/conf/init/nginx/log/run new file mode 100755 index 000000000..30476f6e6 --- /dev/null +++ b/conf/init/nginx/log/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec svlogd /var/log/nginx/ \ No newline at end of file diff --git a/conf/init/nginx.sh b/conf/init/nginx/run similarity index 100% rename from conf/init/nginx.sh rename to conf/init/nginx/run diff --git a/conf/init/preplogsdir.sh b/conf/init/preplogsdir.sh new file mode 100755 index 000000000..8d9c67bfd --- /dev/null +++ b/conf/init/preplogsdir.sh @@ -0,0 +1,8 @@ +#! /bin/sh + +echo 'Linking config files to logs directory' +for svc in `ls /etc/service/` +do + mkdir -p /var/log/$svc + ln -s /svlogd_config /var/log/$svc/config +done diff --git a/conf/init/svlogd_config b/conf/init/svlogd_config new file mode 100644 index 000000000..de7984f15 --- /dev/null +++ b/conf/init/svlogd_config @@ -0,0 +1,2 @@ +s100000000 +t86400 diff --git a/conf/init/tutumdocker/log/run b/conf/init/tutumdocker/log/run new file mode 100755 index 000000000..dbabad38b --- /dev/null +++ b/conf/init/tutumdocker/log/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec svlogd /var/log/tutumdocker/ \ No newline at end of file diff --git a/conf/init/tutumdocker.sh b/conf/init/tutumdocker/run similarity index 99% rename from conf/init/tutumdocker.sh rename to conf/init/tutumdocker/run index f5c56b3ce..9221134b9 100755 --- a/conf/init/tutumdocker.sh +++ b/conf/init/tutumdocker/run @@ -92,6 +92,5 @@ if [ "$PORT" ] then exec docker -d -H 0.0.0.0:$PORT else - - docker -d -D -e lxc + docker -d -D -e lxc 2>&1 fi \ No newline at end of file diff --git a/conf/init/webhookworker/log/run b/conf/init/webhookworker/log/run new file mode 100755 index 000000000..6738f16f8 --- /dev/null +++ b/conf/init/webhookworker/log/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec svlogd -t /var/log/webhookworker/ \ No newline at end of file diff --git a/conf/init/webhookworker.sh b/conf/init/webhookworker/run similarity index 51% rename from conf/init/webhookworker.sh rename to conf/init/webhookworker/run index 7ab6340d8..04521552a 100755 --- a/conf/init/webhookworker.sh +++ b/conf/init/webhookworker/run @@ -3,6 +3,6 @@ echo 'Starting webhook worker' cd / -venv/bin/python -m workers.webhookworker --log=/mnt/logs/webhookworker.log +venv/bin/python -m workers.webhookworker echo 'Webhook worker exited' \ No newline at end of file diff --git a/conf/logging.conf b/conf/logging.conf index 2061a2375..4023e7743 100644 --- a/conf/logging.conf +++ b/conf/logging.conf @@ -1,38 +1,38 @@ [loggers] -keys=root, gunicorn.error, gunicorn.access +keys=root, gunicorn.error, gunicorn.access, application.profiler [handlers] -keys=error_file +keys=console [formatters] keys=generic [logger_application.profiler] level=DEBUG -handlers=error_file +handlers=console propagate=0 qualname=application.profiler [logger_root] level=DEBUG -handlers=error_file +handlers=console [logger_gunicorn.error] level=INFO -handlers=error_file +handlers=console propagate=1 qualname=gunicorn.error [logger_gunicorn.access] level=INFO -handlers=error_file +handlers=console propagate=0 qualname=gunicorn.access -[handler_error_file] -class=logging.FileHandler +[handler_console] +class=StreamHandler formatter=generic -args=('/mnt/logs/application.log',) +args=(sys.stdout, ) [formatter_generic] format=%(asctime)s [%(process)d] [%(levelname)s] [%(name)s] %(message)s diff --git a/conf/logging_local.conf b/conf/logging_local.conf deleted file mode 100644 index 4023e7743..000000000 --- a/conf/logging_local.conf +++ /dev/null @@ -1,39 +0,0 @@ -[loggers] -keys=root, gunicorn.error, gunicorn.access, application.profiler - -[handlers] -keys=console - -[formatters] -keys=generic - -[logger_application.profiler] -level=DEBUG -handlers=console -propagate=0 -qualname=application.profiler - -[logger_root] -level=DEBUG -handlers=console - -[logger_gunicorn.error] -level=INFO -handlers=console -propagate=1 -qualname=gunicorn.error - -[logger_gunicorn.access] -level=INFO -handlers=console -propagate=0 -qualname=gunicorn.access - -[handler_console] -class=StreamHandler -formatter=generic -args=(sys.stdout, ) - -[formatter_generic] -format=%(asctime)s [%(process)d] [%(levelname)s] [%(name)s] %(message)s -class=logging.Formatter diff --git a/conf/logrotate/quay-logrotate b/conf/logrotate/quay-logrotate deleted file mode 100644 index 1a6678639..000000000 --- a/conf/logrotate/quay-logrotate +++ /dev/null @@ -1,41 +0,0 @@ -/mnt/logs/nginx.access.log { - daily - rotate 7 - compress - delaycompress - missingok - notifempty - create 644 root root - - postrotate - kill -USR1 `cat /mnt/logs/nginx.pid` - endscript -} - -/mnt/logs/nginx.error.log { - daily - rotate 7 - compress - delaycompress - missingok - notifempty - create 644 root root - - postrotate - kill -USR1 `cat /mnt/logs/nginx.pid` - endscript -} - -/mnt/logs/application.log { - daily - rotate 7 - compress - delaycompress - missingok - notifempty - create 644 ubuntu ubuntu - - postrotate - kill -USR1 `cat /mnt/logs/gunicorn.pid` - endscript -} \ No newline at end of file diff --git a/conf/root-base.conf b/conf/root-base.conf index b4b9beb90..31c32d25d 100644 --- a/conf/root-base.conf +++ b/conf/root-base.conf @@ -1,5 +1,5 @@ pid /tmp/nginx.pid; -error_log /mnt/logs/nginx.error.log; +error_log /var/log/nginx/nginx.error.log; events { worker_connections 1024; diff --git a/conf/server-base.conf b/conf/server-base.conf index f37d83bba..7ae5eba2c 100644 --- a/conf/server-base.conf +++ b/conf/server-base.conf @@ -1,5 +1,5 @@ client_max_body_size 8G; -client_body_temp_path /mnt/logs/client_body 1 2; +client_body_temp_path /var/log/nginx/client_body 1 2; server_name _; keepalive_timeout 5; @@ -20,5 +20,5 @@ location / { proxy_pass http://app_server; proxy_read_timeout 2000; - proxy_temp_path /mnt/logs/proxy_temp 1 2; + proxy_temp_path /var/log/nginx/proxy_temp 1 2; } \ No newline at end of file diff --git a/workers/diffsworker.py b/workers/diffsworker.py index c5d9b2b5a..85b615cbe 100644 --- a/workers/diffsworker.py +++ b/workers/diffsworker.py @@ -33,16 +33,7 @@ class DiffsWorker(Worker): return True -parser = argparse.ArgumentParser(description='Worker daemon to compute diffs') -parser.add_argument('--log', help='Specify the log file for the worker as a daemon.') -args = parser.parse_args() - -if args.log is not None: - handler = logging.FileHandler(args.log) -else: - handler = logging.StreamHandler() -handler.setFormatter(formatter) -root_logger.addHandler(handler) +logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False) worker = DiffsWorker(image_diff_queue) -worker.start() \ No newline at end of file +worker.start() diff --git a/workers/dockerfilebuild.py b/workers/dockerfilebuild.py index 6efa69909..084905e91 100644 --- a/workers/dockerfilebuild.py +++ b/workers/dockerfilebuild.py @@ -21,7 +21,7 @@ from collections import defaultdict from data.queue import dockerfile_build_queue from data import model from workers.worker import Worker, WorkerUnhealthyException, JobException -from app import app, userfiles as user_files, build_logs +from app import userfiles as user_files, build_logs from util.safetar import safe_extractall from util.dockerfileparse import parse_dockerfile, ParsedDockerfile, serialize_dockerfile @@ -550,27 +550,12 @@ class DockerfileBuildWorker(Worker): desc = 'Worker daemon to monitor dockerfile build' parser = argparse.ArgumentParser(description=desc) -parser.add_argument('-D', action='store_true', default=False, - help='Run the worker in daemon mode.') -parser.add_argument('--log', default='dockerfilebuild.log', - help='Specify the log file for the worker as a daemon.') parser.add_argument('--cachegb', default=20, type=float, help='Maximum cache size in gigabytes.') args = parser.parse_args() +logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False) worker = DockerfileBuildWorker(args.cachegb, dockerfile_build_queue, reservation_seconds=RESERVATION_TIME) - -if args.D: - handler = logging.FileHandler(args.log) - handler.setFormatter(formatter) - root_logger.addHandler(handler) - with daemon.DaemonContext(files_preserve=[handler.stream]): - worker.start() - -else: - handler = logging.StreamHandler() - handler.setFormatter(formatter) - root_logger.addHandler(handler) - worker.start(start_status_server_port=8000) +worker.start(start_status_server_port=8000) diff --git a/workers/webhookworker.py b/workers/webhookworker.py index f3d193ee9..2b785acb6 100644 --- a/workers/webhookworker.py +++ b/workers/webhookworker.py @@ -34,17 +34,7 @@ class WebhookWorker(Worker): return True - -parser = argparse.ArgumentParser(description='Worker daemon to send webhooks') -parser.add_argument('--log', help='Specify the log file for the worker as a daemon.') -args = parser.parse_args() - -if args.log is not None: - handler = logging.FileHandler(args.log) -else: - handler = logging.StreamHandler() -handler.setFormatter(formatter) -root_logger.addHandler(handler) +logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False) worker = WebhookWorker(webhook_queue, poll_period_seconds=15, reservation_seconds=3600)