From 32a4cadac9072d630146e0fb667aec146fcd186f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 4 Mar 2016 12:01:55 +0100 Subject: [PATCH] Add cron image and playbook Add cron image and playbook for logrotate. The "common" Ansible playbook includes configuration files for logrotate. At this point the operator cannot customize/override the logrotate configuration. Closes-Bug: #1553244 Change-Id: Ic9fdda9a273c9ccd90502f0acc7614d2c7157dca --- ansible/roles/common/defaults/main.yml | 4 +++ ansible/roles/common/tasks/config.yml | 26 +++++++++++++++++++ ansible/roles/common/tasks/start.yml | 11 ++++++++ .../templates/cron-logrotate-ansible.conf.j2 | 3 +++ .../templates/cron-logrotate-cinder.conf.j2 | 3 +++ .../templates/cron-logrotate-glance.conf.j2 | 3 +++ .../templates/cron-logrotate-global.conf.j2 | 21 +++++++++++++++ .../templates/cron-logrotate-haproxy.conf.j2 | 3 +++ .../templates/cron-logrotate-heat.conf.j2 | 3 +++ .../cron-logrotate-keepalived.conf.j2 | 3 +++ .../templates/cron-logrotate-keystone.conf.j2 | 5 ++++ .../templates/cron-logrotate-magnum.conf.j2 | 3 +++ .../templates/cron-logrotate-manila.conf.j2 | 3 +++ .../templates/cron-logrotate-mariadb.conf.j2 | 3 +++ .../templates/cron-logrotate-mistral.conf.j2 | 3 +++ .../templates/cron-logrotate-murano.conf.j2 | 3 +++ .../templates/cron-logrotate-neutron.conf.j2 | 3 +++ .../templates/cron-logrotate-nova.conf.j2 | 3 +++ .../templates/cron-logrotate-rabbitmq.conf.j2 | 3 +++ .../templates/cron-logrotate-swift.conf.j2 | 3 +++ ansible/roles/common/templates/cron.json.j2 | 22 ++++++++++++++++ .../common/templates/heka-keystone.toml.j2 | 3 ++- .../common/templates/heka-mariadb.toml.j2 | 3 ++- .../common/templates/heka-openstack.toml.j2 | 3 ++- .../common/templates/heka-rabbitmq.toml.j2 | 3 ++- docker/cron/Dockerfile.j2 | 23 ++++++++++++++++ docker/cron/extend_start.sh | 7 +++++ kolla/common/config.py | 6 ++--- tools/cleanup-containers | 1 + 29 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 ansible/roles/common/templates/cron-logrotate-ansible.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-cinder.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-glance.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-global.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-haproxy.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-heat.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-keepalived.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-keystone.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-magnum.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-manila.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-mariadb.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-mistral.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-murano.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-neutron.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-nova.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-rabbitmq.conf.j2 create mode 100644 ansible/roles/common/templates/cron-logrotate-swift.conf.j2 create mode 100644 ansible/roles/common/templates/cron.json.j2 create mode 100644 docker/cron/Dockerfile.j2 create mode 100644 docker/cron/extend_start.sh diff --git a/ansible/roles/common/defaults/main.yml b/ansible/roles/common/defaults/main.yml index bb57228671..26abea99ab 100644 --- a/ansible/roles/common/defaults/main.yml +++ b/ansible/roles/common/defaults/main.yml @@ -13,3 +13,7 @@ ansible_image_full: "{{ ansible_image }}:{{ ansible_tag }}" heka_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-heka" heka_tag: "{{ openstack_release }}" heka_image_full: "{{ heka_image }}:{{ heka_tag }}" + +cron_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-cron" +cron_tag: "{{ openstack_release }}" +cron_image_full: "{{ cron_image }}:{{ cron_tag }}" diff --git a/ansible/roles/common/tasks/config.yml b/ansible/roles/common/tasks/config.yml index 46b6ddc622..ecc5d28e92 100644 --- a/ansible/roles/common/tasks/config.yml +++ b/ansible/roles/common/tasks/config.yml @@ -15,6 +15,8 @@ recurse: yes with_items: - "heka" + - "cron" + - "cron/logrotate" - name: Copying over config.json files for services template: @@ -22,6 +24,7 @@ dest: "{{ node_config_directory }}/{{ item }}/config.json" with_items: - "heka" + - "cron" - name: Copying over heka config files template: @@ -64,3 +67,26 @@ with_items: - "elasticsearch" when: "{{ enable_central_logging | bool }}" + +- name: Copying over cron logrotate config files + template: + src: "cron-logrotate-{{ item }}.conf.j2" + dest: "{{ node_config_directory }}/cron/logrotate/{{ item }}.conf" + with_items: + - "ansible" + - "cinder" + - "glance" + - "global" + - "haproxy" + - "heat" + - "keepalived" + - "keystone" + - "magnum" + - "manila" + - "mariadb" + - "mistral" + - "murano" + - "neutron" + - "nova" + - "rabbitmq" + - "swift" diff --git a/ansible/roles/common/tasks/start.yml b/ansible/roles/common/tasks/start.yml index c6e44d5982..b3d3a3096b 100644 --- a/ansible/roles/common/tasks/start.yml +++ b/ansible/roles/common/tasks/start.yml @@ -28,3 +28,14 @@ - "/dev/:/dev/" - "/run/:/run/" - "kolla_logs:/var/log/kolla/" + +- name: Starting cron container + kolla_docker: + action: "start_container" + common_options: "{{ docker_common_options }}" + image: "{{ cron_image_full }}" + name: "cron" + volumes: + - "{{ node_config_directory }}/cron/:{{ container_config_directory }}/:ro" + - "heka_socket:/var/lib/kolla/heka/" + - "kolla_logs:/var/log/kolla/" diff --git a/ansible/roles/common/templates/cron-logrotate-ansible.conf.j2 b/ansible/roles/common/templates/cron-logrotate-ansible.conf.j2 new file mode 100644 index 0000000000..3bc0f435b0 --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-ansible.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/ansible.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-cinder.conf.j2 b/ansible/roles/common/templates/cron-logrotate-cinder.conf.j2 new file mode 100644 index 0000000000..b5e59abd26 --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-cinder.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/cinder/*.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-glance.conf.j2 b/ansible/roles/common/templates/cron-logrotate-glance.conf.j2 new file mode 100644 index 0000000000..5b20985bd0 --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-glance.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/glance/*.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-global.conf.j2 b/ansible/roles/common/templates/cron-logrotate-global.conf.j2 new file mode 100644 index 0000000000..c21e3d1c07 --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-global.conf.j2 @@ -0,0 +1,21 @@ +weekly + +rotate 6 + +copytruncate + +compress + +delaycompress + +notifempty + +missingok + +minsize 30M + +maxsize 100M + +su root kolla + +include /etc/logrotate.d diff --git a/ansible/roles/common/templates/cron-logrotate-haproxy.conf.j2 b/ansible/roles/common/templates/cron-logrotate-haproxy.conf.j2 new file mode 100644 index 0000000000..7af26dd38b --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-haproxy.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/haproxy/haproxy.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-heat.conf.j2 b/ansible/roles/common/templates/cron-logrotate-heat.conf.j2 new file mode 100644 index 0000000000..7f5e89a77e --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-heat.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/heat/*.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-keepalived.conf.j2 b/ansible/roles/common/templates/cron-logrotate-keepalived.conf.j2 new file mode 100644 index 0000000000..0346c051d8 --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-keepalived.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/haproxy/keepalived.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-keystone.conf.j2 b/ansible/roles/common/templates/cron-logrotate-keystone.conf.j2 new file mode 100644 index 0000000000..22dded903d --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-keystone.conf.j2 @@ -0,0 +1,5 @@ +{% set apache_dir = 'apache2' if kolla_base_distro in ['ubuntu', 'debian'] else 'httpd' %} +"/var/log/kolla/keystone/*.log" +"/var/log/kolla/{{ apache_dir }}/keystone-apache-*.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-magnum.conf.j2 b/ansible/roles/common/templates/cron-logrotate-magnum.conf.j2 new file mode 100644 index 0000000000..4b2c2af4e6 --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-magnum.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/magnum/*.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-manila.conf.j2 b/ansible/roles/common/templates/cron-logrotate-manila.conf.j2 new file mode 100644 index 0000000000..9b9719514f --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-manila.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/manila/*.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-mariadb.conf.j2 b/ansible/roles/common/templates/cron-logrotate-mariadb.conf.j2 new file mode 100644 index 0000000000..8543983e04 --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-mariadb.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/mariadb/*.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-mistral.conf.j2 b/ansible/roles/common/templates/cron-logrotate-mistral.conf.j2 new file mode 100644 index 0000000000..e8e6da8e39 --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-mistral.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/mistral/*.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-murano.conf.j2 b/ansible/roles/common/templates/cron-logrotate-murano.conf.j2 new file mode 100644 index 0000000000..ab33090192 --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-murano.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/murano/*.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-neutron.conf.j2 b/ansible/roles/common/templates/cron-logrotate-neutron.conf.j2 new file mode 100644 index 0000000000..f4c2268292 --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-neutron.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/neutron/*.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-nova.conf.j2 b/ansible/roles/common/templates/cron-logrotate-nova.conf.j2 new file mode 100644 index 0000000000..657a994da1 --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-nova.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/nova/*.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-rabbitmq.conf.j2 b/ansible/roles/common/templates/cron-logrotate-rabbitmq.conf.j2 new file mode 100644 index 0000000000..cf2dc3f367 --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-rabbitmq.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/rabbitmq/*.log" +{ +} diff --git a/ansible/roles/common/templates/cron-logrotate-swift.conf.j2 b/ansible/roles/common/templates/cron-logrotate-swift.conf.j2 new file mode 100644 index 0000000000..0ad2badf1b --- /dev/null +++ b/ansible/roles/common/templates/cron-logrotate-swift.conf.j2 @@ -0,0 +1,3 @@ +"/var/log/kolla/swift/*.log" +{ +} diff --git a/ansible/roles/common/templates/cron.json.j2 b/ansible/roles/common/templates/cron.json.j2 new file mode 100644 index 0000000000..d6c51d8f0c --- /dev/null +++ b/ansible/roles/common/templates/cron.json.j2 @@ -0,0 +1,22 @@ +{% set cron_cmd = 'cron -f' if kolla_base_distro in ['ubuntu', 'debian'] else 'crond -s -n' %} +{% set services = ["ansible", "cinder", "glance", "haproxy", "heat", "keepalived", "keystone", "magnum", "manila", "mariadb", "mistral", "murano", "neutron", "nova", "rabbitmq", "swift"] %} +{ + "command": "{{ cron_cmd }}", + "config_files": [ + { + "source": "{{ container_config_directory }}/logrotate/global.conf", + "dest": "/etc/logrotate.conf", + "owner": "root", + "perm": "0644" + }, +{% for service in services %} + { + "source": "{{ container_config_directory }}/logrotate/{{ service }}.conf", + "dest": "/etc/logrotate.d/{{ service }}.conf", + "owner": "root", + "perm": "0644" + }{% if not loop.last %},{% endif %} +{% endfor %} + + ] +} diff --git a/ansible/roles/common/templates/heka-keystone.toml.j2 b/ansible/roles/common/templates/heka-keystone.toml.j2 index 5747d417ce..6d7874d566 100644 --- a/ansible/roles/common/templates/heka-keystone.toml.j2 +++ b/ansible/roles/common/templates/heka-keystone.toml.j2 @@ -9,5 +9,6 @@ filename = "lua_decoders/os_keystone_apache_log.lua" type = "LogstreamerInput" decoder = "keystone_apache_log_decoder" log_directory = "/var/log/kolla" -file_match = '{{ apache_dir }}/keystone-apache-(?P.+)-access\.log' +file_match = '{{ apache_dir }}/keystone-apache-(?P.+)-access\.log\.?(?P\d*)$' +priority = ["^Seq"] differentiator = ["keystone-apache-", "Service"] diff --git a/ansible/roles/common/templates/heka-mariadb.toml.j2 b/ansible/roles/common/templates/heka-mariadb.toml.j2 index 85fad0d042..07d7105410 100644 --- a/ansible/roles/common/templates/heka-mariadb.toml.j2 +++ b/ansible/roles/common/templates/heka-mariadb.toml.j2 @@ -6,5 +6,6 @@ filename = "lua_decoders/os_mysql_log.lua" type = "LogstreamerInput" decoder = "mariadb_log_decoder" log_directory = "/var/log/kolla" -file_match = 'mariadb/mariadb\.log' +file_match = 'mariadb/mariadb\.log\.?(?P\d*)$' +priority = ["^Seq"] differentiator = ['mariadb'] diff --git a/ansible/roles/common/templates/heka-openstack.toml.j2 b/ansible/roles/common/templates/heka-openstack.toml.j2 index 32c20514a2..9cf3782db5 100644 --- a/ansible/roles/common/templates/heka-openstack.toml.j2 +++ b/ansible/roles/common/templates/heka-openstack.toml.j2 @@ -6,5 +6,6 @@ filename = "lua_decoders/os_openstack_log.lua" type = "LogstreamerInput" decoder = "openstack_log_decoder" log_directory = "/var/log/kolla" -file_match = '(?Pnova|glance|keystone|neutron|cinder|heat|murano|magnum|mistral|manila)/(?P.*)\.log' +file_match = '(?Pnova|glance|keystone|neutron|cinder|heat|murano|magnum|mistral|manila)/(?P.*)\.log\.?(?P\d*)$' +priority = ["^Seq"] differentiator = ["Service", "_", "Program"] diff --git a/ansible/roles/common/templates/heka-rabbitmq.toml.j2 b/ansible/roles/common/templates/heka-rabbitmq.toml.j2 index d8e16ec3be..d2c49aa1e7 100644 --- a/ansible/roles/common/templates/heka-rabbitmq.toml.j2 +++ b/ansible/roles/common/templates/heka-rabbitmq.toml.j2 @@ -13,5 +13,6 @@ type = "LogstreamerInput" decoder = "rabbitmq_log_decoder" splitter = "rabbitmq_log_splitter" log_directory = "/var/log/kolla" -file_match = 'rabbitmq/(?Prabbit.*)\.log' +file_match = 'rabbitmq/(?Prabbit.*)\.log\.?(?P\d*)$' +priority = ["^Seq"] differentiator = ["Service"] diff --git a/docker/cron/Dockerfile.j2 b/docker/cron/Dockerfile.j2 new file mode 100644 index 0000000000..fd7b53cd5e --- /dev/null +++ b/docker/cron/Dockerfile.j2 @@ -0,0 +1,23 @@ +FROM {{ namespace }}/{{ image_prefix }}base:{{ tag }} +MAINTAINER {{ maintainer }} + +{% if base_distro in ['centos', 'fedora', 'oraclelinux', 'rhel'] %} + +RUN yum -y install \ + cronie \ + logrotate \ + && yum clean all + +{% elif base_distro in ['ubuntu', 'debian'] %} + +RUN apt-get install -y --no-install-recommends \ + cron \ + logrotate \ + && apt-get clean + +{% endif %} + +COPY extend_start.sh /usr/local/bin/kolla_extend_start +RUN chmod 755 /usr/local/bin/kolla_extend_start + +{{ include_footer }} diff --git a/docker/cron/extend_start.sh b/docker/cron/extend_start.sh new file mode 100644 index 0000000000..08efca96fa --- /dev/null +++ b/docker/cron/extend_start.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# NOTE(elemoine): the cron daemon sends its logs to /dev/log. Heka's log socket +# is at /var/lib/kolla/heka/log so we symlink /dev/log to that location. +if [[ ! -h /dev/log ]]; then + ln -sf /var/lib/kolla/heka/log /dev/log +fi diff --git a/kolla/common/config.py b/kolla/common/config.py index 2eeb8c9ca5..797229fb1c 100644 --- a/kolla/common/config.py +++ b/kolla/common/config.py @@ -25,7 +25,7 @@ INSTALL_TYPE_CHOICES = ['binary', 'source', 'rdo', 'rhos'] _PROFILE_OPTS = [ cfg.ListOpt('infra', - default=['ceph', 'mariadb', 'haproxy', + default=['ceph', 'cron', 'mariadb', 'haproxy', 'keepalived', 'kolla-toolbox', 'memcached', 'mongodb', 'openvswitch', 'rabbitmq', 'heka'], help='Infra images'), @@ -39,13 +39,13 @@ _PROFILE_OPTS = [ 'magnum', 'mistral', 'trove,' 'zaqar', 'zookeeper'], help='Aux Images'), cfg.ListOpt('default', - default=['kolla-toolbox', 'glance', 'haproxy', + default=['cron', 'kolla-toolbox', 'glance', 'haproxy', 'heat', 'horizon', 'keepalived', 'keystone', 'memcached', 'mariadb', 'neutron', 'nova', 'openvswitch', 'rabbitmq', 'heka'], help='Default images'), cfg.ListOpt('gate', - default=['glance', 'haproxy', 'keepalived', 'keystone', + default=['cron', 'glance', 'haproxy', 'keepalived', 'keystone', 'kolla-toolbox', 'mariadb', 'memcached', 'neutron', 'nova', 'openvswitch', 'rabbitmq', 'heka'], help='Gate images'), diff --git a/tools/cleanup-containers b/tools/cleanup-containers index 38772e6547..da716b0607 100755 --- a/tools/cleanup-containers +++ b/tools/cleanup-containers @@ -14,6 +14,7 @@ else bootstrap_{ceph_mon,cinder,glance,heat,heka,ironic,ironic_pxe,keystone,magnum,mistral,mongodb,murano,neutron,nova,nova_compute} \ cinder_{volume,scheduler,backup,api} \ ceph_{mon,rgw} \ + cron \ elasticsearch \ glance_{api,registry} \ haproxy \