Rework the config to use runit logging.

This commit is contained in:
Jake Moshenko 2014-05-18 17:19:14 -04:00
parent 334b4634d7
commit 212a4650f4
29 changed files with 58 additions and 165 deletions

View file

@ -38,9 +38,11 @@ ADD test test
ADD conf conf ADD conf conf
RUN rm -rf /conf/stack RUN rm -rf /conf/stack
ADD conf/init/tutumdocker.sh /etc/service/tutumdocker/run ADD conf/init/svlogd_config /svlogd_config
ADD conf/init/dockerfilebuild.sh /etc/service/dockerfilebuild/run 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"] CMD ["/sbin/my_init"]

View file

@ -45,11 +45,12 @@ ADD application.py application.py
ADD config.py config.py ADD config.py config.py
ADD initdb.py initdb.py ADD initdb.py initdb.py
ADD conf/init/mklogsdir.sh /etc/my_init.d/ ADD conf/init/svlogd_config /svlogd_config
ADD conf/init/gunicorn.sh /etc/service/gunicorn/run ADD conf/init/preplogsdir.sh /etc/my_init.d/
ADD conf/init/nginx.sh /etc/service/nginx/run ADD conf/init/gunicorn /etc/service/gunicorn
ADD conf/init/diffsworker.sh /etc/service/diffsworker/run ADD conf/init/nginx /etc/service/nginx
ADD conf/init/webhookworker.sh /etc/service/webhookworker/run ADD conf/init/diffsworker /etc/service/diffsworker
ADD conf/init/webhookworker /etc/service/webhookworker
RUN cd grunt && npm install RUN cd grunt && npm install
RUN cd grunt && grunt RUN cd grunt && grunt
@ -59,7 +60,7 @@ ADD test test
RUN TEST=true venv/bin/python -m unittest discover RUN TEST=true venv/bin/python -m unittest discover
RUN rm -rf /conf/stack RUN rm -rf /conf/stack
VOLUME ["/conf/stack", "/mnt/logs"] VOLUME ["/conf/stack", "/var/log"]
EXPOSE 443 80 EXPOSE 443 80

View file

@ -67,5 +67,5 @@ application.teardown_request(close_db)
application.request_class = RequestWithId application.request_class = RequestWithId
if __name__ == '__main__': 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') application.run(port=5000, debug=True, threaded=True, host='0.0.0.0')

View file

@ -2,6 +2,5 @@ bind = 'unix:/tmp/gunicorn.sock'
workers = 8 workers = 8
worker_class = 'gevent' worker_class = 'gevent'
timeout = 2000 timeout = 2000
pidfile = '/tmp/gunicorn.pid'
logconfig = 'conf/logging.conf' logconfig = 'conf/logging.conf'
pythonpath = '.' pythonpath = '.'

View file

@ -3,5 +3,5 @@ workers = 2
worker_class = 'gevent' worker_class = 'gevent'
timeout = 2000 timeout = 2000
daemon = False daemon = False
logconfig = 'conf/logging_local.conf' logconfig = 'conf/logging.conf'
pythonpath = '.' pythonpath = '.'

View file

@ -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; types_hash_max_size 2048;
include /usr/local/nginx/conf/mime.types.default; include /usr/local/nginx/conf/mime.types.default;
default_type application/octet-stream; default_type application/octet-stream;
access_log /mnt/logs/nginx.access.log logstash_json; access_log /var/log/nginx/nginx.access.log;
sendfile on; sendfile on;
gzip on; gzip on;

2
conf/init/diffsworker/log/run Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd /var/log/diffsworker/

View file

@ -3,6 +3,6 @@
echo 'Starting diffs worker' echo 'Starting diffs worker'
cd / cd /
venv/bin/python -m workers.diffsworker --log=/mnt/logs/diffsworker.log venv/bin/python -m workers.diffsworker
echo 'Diffs worker exited' echo 'Diffs worker exited'

View file

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd /var/log/dockerfilebuild/

2
conf/init/gunicorn/log/run Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd /var/log/gunicorn/

View file

@ -1,4 +0,0 @@
#! /bin/sh
echo 'Creating logs directory'
mkdir -p /mnt/logs

2
conf/init/nginx/log/run Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd /var/log/nginx/

8
conf/init/preplogsdir.sh Executable file
View file

@ -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

2
conf/init/svlogd_config Normal file
View file

@ -0,0 +1,2 @@
s100000000
t86400

2
conf/init/tutumdocker/log/run Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd /var/log/tutumdocker/

View file

@ -92,6 +92,5 @@ if [ "$PORT" ]
then then
exec docker -d -H 0.0.0.0:$PORT exec docker -d -H 0.0.0.0:$PORT
else else
docker -d -D -e lxc 2>&1
docker -d -D -e lxc
fi fi

View file

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd -t /var/log/webhookworker/

View file

@ -3,6 +3,6 @@
echo 'Starting webhook worker' echo 'Starting webhook worker'
cd / cd /
venv/bin/python -m workers.webhookworker --log=/mnt/logs/webhookworker.log venv/bin/python -m workers.webhookworker
echo 'Webhook worker exited' echo 'Webhook worker exited'

View file

@ -1,38 +1,38 @@
[loggers] [loggers]
keys=root, gunicorn.error, gunicorn.access keys=root, gunicorn.error, gunicorn.access, application.profiler
[handlers] [handlers]
keys=error_file keys=console
[formatters] [formatters]
keys=generic keys=generic
[logger_application.profiler] [logger_application.profiler]
level=DEBUG level=DEBUG
handlers=error_file handlers=console
propagate=0 propagate=0
qualname=application.profiler qualname=application.profiler
[logger_root] [logger_root]
level=DEBUG level=DEBUG
handlers=error_file handlers=console
[logger_gunicorn.error] [logger_gunicorn.error]
level=INFO level=INFO
handlers=error_file handlers=console
propagate=1 propagate=1
qualname=gunicorn.error qualname=gunicorn.error
[logger_gunicorn.access] [logger_gunicorn.access]
level=INFO level=INFO
handlers=error_file handlers=console
propagate=0 propagate=0
qualname=gunicorn.access qualname=gunicorn.access
[handler_error_file] [handler_console]
class=logging.FileHandler class=StreamHandler
formatter=generic formatter=generic
args=('/mnt/logs/application.log',) args=(sys.stdout, )
[formatter_generic] [formatter_generic]
format=%(asctime)s [%(process)d] [%(levelname)s] [%(name)s] %(message)s format=%(asctime)s [%(process)d] [%(levelname)s] [%(name)s] %(message)s

View file

@ -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

View file

@ -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
}

View file

@ -1,5 +1,5 @@
pid /tmp/nginx.pid; pid /tmp/nginx.pid;
error_log /mnt/logs/nginx.error.log; error_log /var/log/nginx/nginx.error.log;
events { events {
worker_connections 1024; worker_connections 1024;

View file

@ -1,5 +1,5 @@
client_max_body_size 8G; 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 _; server_name _;
keepalive_timeout 5; keepalive_timeout 5;
@ -20,5 +20,5 @@ location / {
proxy_pass http://app_server; proxy_pass http://app_server;
proxy_read_timeout 2000; proxy_read_timeout 2000;
proxy_temp_path /mnt/logs/proxy_temp 1 2; proxy_temp_path /var/log/nginx/proxy_temp 1 2;
} }

View file

@ -33,16 +33,7 @@ class DiffsWorker(Worker):
return True return True
parser = argparse.ArgumentParser(description='Worker daemon to compute diffs') logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False)
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)
worker = DiffsWorker(image_diff_queue) worker = DiffsWorker(image_diff_queue)
worker.start() worker.start()

View file

@ -21,7 +21,7 @@ from collections import defaultdict
from data.queue import dockerfile_build_queue from data.queue import dockerfile_build_queue
from data import model from data import model
from workers.worker import Worker, WorkerUnhealthyException, JobException 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.safetar import safe_extractall
from util.dockerfileparse import parse_dockerfile, ParsedDockerfile, serialize_dockerfile from util.dockerfileparse import parse_dockerfile, ParsedDockerfile, serialize_dockerfile
@ -550,27 +550,12 @@ class DockerfileBuildWorker(Worker):
desc = 'Worker daemon to monitor dockerfile build' desc = 'Worker daemon to monitor dockerfile build'
parser = argparse.ArgumentParser(description=desc) 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, parser.add_argument('--cachegb', default=20, type=float,
help='Maximum cache size in gigabytes.') help='Maximum cache size in gigabytes.')
args = parser.parse_args() args = parser.parse_args()
logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False)
worker = DockerfileBuildWorker(args.cachegb, dockerfile_build_queue, worker = DockerfileBuildWorker(args.cachegb, dockerfile_build_queue,
reservation_seconds=RESERVATION_TIME) reservation_seconds=RESERVATION_TIME)
worker.start(start_status_server_port=8000)
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)

View file

@ -34,17 +34,7 @@ class WebhookWorker(Worker):
return True return True
logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False)
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)
worker = WebhookWorker(webhook_queue, poll_period_seconds=15, worker = WebhookWorker(webhook_queue, poll_period_seconds=15,
reservation_seconds=3600) reservation_seconds=3600)