diff --git a/defaults/main.yml b/defaults/main.yml index 1cdf185..378ee78 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -116,13 +116,17 @@ cloudkitty_processor_init_overrides: {} ## Service Name-Group Mapping cloudkitty_services: cloudkitty-api: - group: cloudkitty_api + group: cloudkitty_all service_name: cloudkitty-api init_config_overrides: "{{ cloudkitty_api_init_overrides }}" + execstarts: "{{ cloudkitty_bin }}/cloudkitty-api" + start_order: 1 cloudkitty-processor: - group: cloudkitty_api + group: cloudkitty_all service_name: cloudkitty-processor init_config_overrides: "{{ cloudkitty_processor_init_overrides }}" + execstarts: "{{ cloudkitty_bin }}/cloudkitty-processor" + start_order: 2 cloudkitty_pip_packages: - cloudkitty @@ -132,6 +136,7 @@ cloudkitty_pip_packages: - PyMySQL - python-memcached - SQLAlchemy>=1.0.10 + - systemd-python - tooz ## (Qdrouterd) integration diff --git a/extras/os-cloudkitty-install.yml b/extras/os-cloudkitty-install.yml index fecb4b5..477473a 100644 --- a/extras/os-cloudkitty-install.yml +++ b/extras/os-cloudkitty-install.yml @@ -29,8 +29,8 @@ - include: common-tasks/os-log-dir-setup.yml vars: log_dirs: - - src: "/openstack/log/{{ inventory_hostname }}-barbican" - dest: "/var/log/barbican" + - src: "/openstack/log/{{ inventory_hostname }}-cloudkitty" + dest: "/var/log/cloudkitty" roles: - role: "os_cloudkitty" diff --git a/handlers/main.yml b/handlers/main.yml index 34f3380..68d61dc 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -14,13 +14,10 @@ # limitations under the License. - name: Stop services - service: - name: "{{ item.value.service_name }}" - enabled: yes + systemd: + name: "{{ item.service_name }}" state: "stopped" - daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}" - with_dict: "{{ cloudkitty_services }}" - when: inventory_hostname in groups[item.value.group] + with_items: "{{ filtered_cloudkitty_services }}" register: _stop until: _stop is success retries: 5 @@ -46,13 +43,10 @@ listen: Restart cloudkitty services - name: Start services - service: - name: "{{ item.value.service_name }}" - enabled: yes + systemd: + name: "{{ item.service_name }}" state: "started" - daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}" - with_dict: "{{ cloudkitty_services }}" - when: inventory_hostname in groups[item.value.group] + with_items: "{{ filtered_cloudkitty_services }}" register: _start until: _start is success retries: 5 diff --git a/releasenotes/notes/journal-log-cfbr504hd9b49612.yaml b/releasenotes/notes/journal-log-cfbr504hd9b49612.yaml new file mode 100644 index 0000000..114aef3 --- /dev/null +++ b/releasenotes/notes/journal-log-cfbr504hd9b49612.yaml @@ -0,0 +1,5 @@ +--- +deprecations: + - The log path, ``/var/log/cloudkitty`` is no longer used to capture service + logs. All logging for the cloudkitty service will now be sent directly to the + systemd journal. diff --git a/tasks/cloudkitty_init_systemd.yml b/tasks/cloudkitty_init_systemd.yml deleted file mode 100644 index d5421ed..0000000 --- a/tasks/cloudkitty_init_systemd.yml +++ /dev/null @@ -1,60 +0,0 @@ ---- -# Copyright 2016, Rackspace US, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -- name: Create TEMP run dir - file: - path: "/var/run/{{ item.value.service_name }}" - state: directory - owner: "{{ cloudkitty_system_user_name }}" - group: "{{ cloudkitty_system_group_name }}" - mode: "02755" - with_dict: "{{ cloudkitty_services }}" - when: inventory_hostname in groups[item.value.group] - -- name: Create TEMP lock dir - file: - path: "/var/lock/{{ item.value.service_name }}" - state: directory - owner: "{{ cloudkitty_system_user_name }}" - group: "{{ cloudkitty_system_group_name }}" - mode: "02755" - with_dict: "{{ cloudkitty_services }}" - when: inventory_hostname in groups[item.value.group] - -- name: Create tempfile.d entry - template: - src: "cloudkitty-systemd-tempfiles.j2" - dest: "/etc/tmpfiles.d/cloudkitty.conf" - mode: "0644" - owner: "root" - group: "root" - with_dict: "{{ cloudkitty_services }}" - when: inventory_hostname in groups[item.value.group] - notify: - - Restart cloudkitty services - -- name: Place the systemd init script - config_template: - src: "cloudkitty-systemd-init.j2" - dest: "/etc/systemd/system/{{ item.value.service_name }}.service" - mode: "0644" - owner: "root" - group: "root" - config_overrides: "{{ item.value.init_config_overrides }}" - config_type: "ini" - with_dict: "{{ cloudkitty_services }}" - when: inventory_hostname in groups[item.value.group] - notify: - - Restart cloudkitty services diff --git a/tasks/cloudkitty_install.yml b/tasks/cloudkitty_install.yml index e1f74a1..afc242e 100644 --- a/tasks/cloudkitty_install.yml +++ b/tasks/cloudkitty_install.yml @@ -26,6 +26,18 @@ retries: 5 delay: 2 +- name: Install developer mode distro packages + package: + pkg: "{{ cloudkitty_developer_mode_distro_packages }}" + state: "{{ cloudkitty_package_state }}" + update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}" + cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" + when: cloudkitty_developer_mode | bool + register: install_packages + until: install_packages is success + retries: 5 + delay: 2 + - name: Create developer mode constraint file copy: dest: "/opt/developer-pip-constraints.txt" diff --git a/tasks/cloudkitty_pre_install.yml b/tasks/cloudkitty_pre_install.yml index 88aca62..1731d07 100644 --- a/tasks/cloudkitty_pre_install.yml +++ b/tasks/cloudkitty_pre_install.yml @@ -48,35 +48,6 @@ tags: - cloudkitty-dirs -- name: Test for log directory or link - shell: | - if [ -h "/var/log/cloudkitty" ]; then - chown -h {{ cloudkitty_system_user_name }}:{{ cloudkitty_system_group_name }} "/var/log/cloudkitty" - chown -R {{ cloudkitty_system_user_name }}:{{ cloudkitty_system_group_name }} "$(readlink /var/log/cloudkitty)" - else - exit 1 - fi - register: log_dir - failed_when: false - changed_when: log_dir.rc != 0 - tags: - - cloudkitty-dirs - - cloudkitty-logs - -- name: Create cloudkitty log dir - file: - path: "{{ item.path }}" - state: directory - owner: "{{ item.owner|default(cloudkitty_system_user_name) }}" - group: "{{ item.group|default(cloudkitty_system_group_name) }}" - mode: "{{ item.mode|default('0755') }}" - with_items: - - { path: "/var/log/cloudkitty" } - when: log_dir.rc != 0 - tags: - - cloudkitty-dirs - - cloudkitty-logs - - name: Create cloudkitty report dir file: path: "{{ cloudkitty_output_basepath }}" diff --git a/tasks/main.yml b/tasks/main.yml index 2941ff8..c3ad7ff 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -68,7 +68,33 @@ when: - inventory_hostname == groups['cloudkitty_all'][0] -- include: "cloudkitty_init_{{ ansible_service_mgr }}.yml" +- name: Run the systemd service role + include_role: + name: systemd_service + private: true + vars: + systemd_user_name: "{{ cloudkitty_system_user_name }}" + systemd_group_name: "{{ cloudkitty_system_group_name }}" + systemd_tempd_prefix: openstack + systemd_slice_name: cloudkitty + systemd_lock_path: /var/lock/cloudkitty + systemd_CPUAccounting: true + systemd_BlockIOAccounting: true + systemd_MemoryAccounting: true + systemd_TasksAccounting: true + systemd_services: + - service_name: "{{ service_var.service_name }}" + enabled: yes + state: started + execstarts: "{{ service_var.execstarts }}" + execreloads: "{{ service_var.execreloads | default([]) }}" + config_overrides: "{{ service_var.init_config_overrides }}" + with_items: "{{ filtered_cloudkitty_services }}" + loop_control: + loop_var: service_var + tags: + - cloudkitty-config + - systemd-service - name: Flush handlers meta: flush_handlers diff --git a/templates/cloudkitty-systemd-init.j2 b/templates/cloudkitty-systemd-init.j2 deleted file mode 100644 index 56c0172..0000000 --- a/templates/cloudkitty-systemd-init.j2 +++ /dev/null @@ -1,34 +0,0 @@ -# {{ ansible_managed }} - -[Unit] -Description=cloudkitty openstack service -After=syslog.target -After=network.target - -[Service] -Type=simple -User={{ cloudkitty_system_user_name }} -Group={{ cloudkitty_system_group_name }} - -{% if program_override is defined %} -ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/cloudkitty/{{ item.value.service_name }}.log -{% else %} -ExecStart={{ cloudkitty_bin }}/{{ item.value.service_name }} {{ program_config_options|default('') }} --log-file=/var/log/cloudkitty/{{ item.value.service_name }}.log -{% endif %} - -# Give a reasonable amount of time for the server to start up/shut down -TimeoutSec=120 -Restart=on-failure -RestartSec=2 - -# This creates a specific slice which all services will operate from -# The accounting options give us the ability to see resource usage through -# the `systemd-cgtop` command. -Slice=cloudkitty.slice -CPUAccounting=true -BlockIOAccounting=true -MemoryAccounting=false -TasksAccounting=true - -[Install] -WantedBy=multi-user.target diff --git a/templates/cloudkitty-systemd-tempfiles.j2 b/templates/cloudkitty-systemd-tempfiles.j2 deleted file mode 100644 index ba489dd..0000000 --- a/templates/cloudkitty-systemd-tempfiles.j2 +++ /dev/null @@ -1,4 +0,0 @@ -# {{ ansible_managed }} - -D /var/lock/{{ item.value.service_name }} 2755 {{ cloudkitty_system_user_name }} {{ cloudkitty_system_group_name }} -D /var/run/{{ item.value.service_name }} 2755 {{ cloudkitty_system_user_name }} {{ cloudkitty_system_group_name }} diff --git a/vars/debian.yml b/vars/debian.yml index 431532f..22e471c 100644 --- a/vars/debian.yml +++ b/vars/debian.yml @@ -18,3 +18,10 @@ cache_timeout: 600 cloudkitty_distro_packages: - git + - python-systemd + - python3-systemd + +cloudkitty_developer_mode_distro_packages: + - build-essential + - git-core + - libsystemd-dev diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..8f1c788 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,31 @@ +--- +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# Compile a list of the services on a host based on whether +# the host is in the host group and the service is enabled. +# The service list is provided in the defined start order. +# +filtered_cloudkitty_services: |- + {% set services = [] %} + {% for key, value in cloudkitty_services.items() %} + {% if (value['group'] in group_names) and + (('condition' not in value) or + ('condition' in value and value['condition'])) %} + {% set _ = value.update({'service_key': key}) %} + {% set _ = services.append(value) %} + {% endif %} + {% endfor %} + {{ services | sort(attribute='start_order') }} diff --git a/vars/redhat.yml b/vars/redhat.yml index 13eed3d..1ace3ef 100644 --- a/vars/redhat.yml +++ b/vars/redhat.yml @@ -15,3 +15,7 @@ cloudkitty_distro_packages: - git + - systemd-python + +cloudkitty_developer_mode_distro_packages: + - systemd-devel diff --git a/vars/suse.yml b/vars/suse.yml index 337c944..263a000 100644 --- a/vars/suse.yml +++ b/vars/suse.yml @@ -15,3 +15,8 @@ cloudkitty_distro_packages: - git-core + - python-systemd + +cloudkitty_developer_mode_distro_packages: + - pkg-config + - systemd-devel