From 9eb319c22b5329f78b2b6c3c4f4744793c633744 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Thu, 8 Mar 2018 20:04:18 -0600 Subject: [PATCH] Convert role to use a common systemd service role This removes the systemd service templates and tasks from this role and leverages a common systemd service role instead. This change removes a lot of code duplication across all roles all without sacrificing features or functionality. The intention of this change is to ensure uniformity and reduce the maintenance burden on the community when sweeping changes are needed. The exterior role is built to be OSA compatible and may be pulled into tree should we deem it necessary. Change-Id: Ie558875fcfbcd92c38d55e2d24087fce90889eaf Signed-off-by: Kevin Carter --- defaults/main.yml | 9 +++- tasks/glance_install.yml | 65 ++++++++++------------------ templates/glance-systemd-init.j2 | 34 --------------- templates/glance-systemd-tmpfiles.j2 | 4 -- 4 files changed, 30 insertions(+), 82 deletions(-) delete mode 100644 templates/glance-systemd-init.j2 delete mode 100644 templates/glance-systemd-tmpfiles.j2 diff --git a/defaults/main.yml b/defaults/main.yml index a3aca6c6..01d96f04 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -249,21 +249,26 @@ glance_services: start_order: 1 wsgi_overrides: "{{ glance_api_uwsgi_ini_overrides }}" wsgi_app: "{{ not glance_enable_v1_api }}" - log_string: "{{ glance_enable_v1_api | ternary('--log-file=', '--logto ') }}" wsgi_name: glance-wsgi-api uwsgi_bind_address: "{{ glance_api_bind_address }}" uwsgi_port: "{{ glance_api_service_port }}" - program_override: >- + execstarts: >- {{ glance_enable_v1_api | ternary( glance_bin ~ '/glance-api', glance_bin ~ '/uwsgi --ini /etc/uwsgi/glance-api.ini') }} + execreloads: >- + {{ glance_enable_v1_api | ternary( + '/bin/kill -HUP $MAINPID', + glance_bin ~ '/uwsgi --reload /var/run/glance-api/glance-api.pid') + }} glance-registry: group: glance_registry service_name: glance-registry condition: "{{ glance_enable_v1_api | bool or glance_enable_v2_registry | bool }}" init_config_overrides: "{{ glance_registry_init_overrides }}" start_order: 2 + execstarts: "{{ glance_bin }}/glance-registry" # Glance uWSGI settings glance_wsgi_processes_max: 16 diff --git a/tasks/glance_install.yml b/tasks/glance_install.yml index 7bcd566c..32507803 100644 --- a/tasks/glance_install.yml +++ b/tasks/glance_install.yml @@ -211,49 +211,30 @@ option: venv_tag value: "{{ glance_venv_tag }}" -- name: Create TEMP run dir - file: - path: "/var/run/{{ item.service_name }}" - state: directory - owner: "{{ glance_system_user_name }}" - group: "{{ glance_system_group_name }}" - mode: "02755" +- name: Run the systemd service role + include_role: + name: systemd_service + private: true + vars: + systemd_user_name: "{{ glance_system_user_name }}" + systemd_group_name: "{{ glance_system_group_name }}" + systemd_tempd_prefix: openstack + systemd_slice_name: glance + system_lock_path: /var/lock/glance + 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_glance_services }}" - -- name: Create TEMP lock dir - file: - path: "/var/lock/{{ item.service_name }}" - state: directory - owner: "{{ glance_system_user_name }}" - group: "{{ glance_system_group_name }}" - mode: "02755" - with_items: "{{ filtered_glance_services }}" - -- name: Create tmpfiles.d entry - template: - src: "glance-systemd-tmpfiles.j2" - dest: "/etc/tmpfiles.d/openstack-{{ item.service_name }}.conf" - mode: "0644" - owner: "root" - group: "root" - with_items: "{{ filtered_glance_services }}" - notify: - - Manage LB - - Restart glance services - -- name: Place the systemd init script - config_template: - src: "glance-systemd-init.j2" - dest: "/etc/systemd/system/{{ item.service_name }}.service" - mode: "0644" - owner: "root" - group: "root" - config_overrides: "{{ item.init_config_overrides }}" - config_type: "ini" - with_items: "{{ filtered_glance_services }}" - notify: - - Manage LB - - Restart glance services + loop_control: + loop_var: service_var - name: Ensure uWSGI directory exists file: diff --git a/templates/glance-systemd-init.j2 b/templates/glance-systemd-init.j2 deleted file mode 100644 index 63c9eabc..00000000 --- a/templates/glance-systemd-init.j2 +++ /dev/null @@ -1,34 +0,0 @@ -# {{ ansible_managed }} - -[Unit] -Description=glance openstack service -After=syslog.target -After=network.target - -[Service] -Type=simple -User={{ glance_system_user_name }} -Group={{ glance_system_group_name }} - -{% if item.program_override is defined %} -ExecStart={{ item.program_override }} {{ item.program_config_options | default('') }} {{ item.log_string | default('--log-file=') }}/var/log/glance/{{ item.service_name }}.log -{% else %} -ExecStart={{ glance_bin }}/{{ item.service_name }} {{ item.program_config_options | default('') }} --log-file=/var/log/glance/{{ item.service_name }}.log -{% endif %} - -# Give a reasonable amount of time for the server to start up/shut down -TimeoutSec=300 -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=glance.slice -CPUAccounting=true -BlockIOAccounting=true -MemoryAccounting=false -TasksAccounting=true - -[Install] -WantedBy=multi-user.target diff --git a/templates/glance-systemd-tmpfiles.j2 b/templates/glance-systemd-tmpfiles.j2 deleted file mode 100644 index 5ade3829..00000000 --- a/templates/glance-systemd-tmpfiles.j2 +++ /dev/null @@ -1,4 +0,0 @@ -# {{ ansible_managed }} - -D /var/lock/{{ item.service_name }} 2755 {{ glance_system_user_name }} {{ glance_system_group_name }} -D /var/run/{{ item.service_name }} 2755 {{ glance_system_user_name }} {{ glance_system_group_name }}