diff --git a/defaults/main.yml b/defaults/main.yml index bc33865..79206e0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -18,16 +18,30 @@ almanach_version: 4.0.9 almanach_collector_program_name: almanach-collector almanach_api_program_name: almanach-api -almanach_service_names: - - "almanach-api" - - "almanach-collector" +almanach_venv_tag: untagged +almanach_bin: "/openstack/venvs/almanach-{{ almanach_venv_tag }}/bin" -almanach_requires_apt_packages: - - python3-pip +almanach_services: + almanach-api: + group: almanach_all + service_name: almanach-api + init_config_overrides: "{{ almanach_api_init_config_overrides }}" + start_order: 1 + execstarts: "{{ almanach_bin }}/almanach-api" + almanach-collector: + group: almanach_all + service_name: almanach-collector + init_config_overrides: "{{ almanach_collector_init_config_overrides }}" + start_order: 2 + execstarts: "{{ almanach_bin }}/almanach-collector" almanach_requires_pip_packages: - virtualenv +almanach_pip_packages: + - "almanach=={{ almanach_version }}" + - systemd-python + almanach_system_user_name: almanach almanach_system_group_name: almanach almanach_system_shell: /bin/false @@ -36,8 +50,6 @@ almanach_system_comment: almanach system user almanach_log_dir: /var/log/almanach almanach_log_file: /var/log/almanach/almanach.log -almanach_app_dir: /opt/almanach - almanach_config_dir: /etc/almanach almanach_config_file: /etc/almanach/almanach.conf almanach_logrotate_config_file: /etc/logrotate.d/almanach diff --git a/handlers/main.yml b/handlers/main.yml index 042d3b7..f941101 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -26,7 +26,7 @@ - name: Restart almanach services systemd: - name: "{{ item }}" + name: "{{ item.service_name }}" state: "restarted" - with_items: "{{ almanach_service_names }}" + with_items: "{{ filtered_almanach_services }}" failed_when: false diff --git a/tasks/almanach_init.yml b/tasks/almanach_init.yml deleted file mode 100644 index 05b9be3..0000000 --- a/tasks/almanach_init.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -# Copyright 2016, Internap 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. - -- include: almanach_init_systemd.yml - vars: - program_name: "{{ almanach_api_program_name }}" - service_name: "almanach-api" - system_user: "{{ almanach_system_user_name }}" - system_group: "{{ almanach_system_group_name }}" - init_config_overrides: "{{ almanach_api_init_config_overrides }}" - -- include: almanach_init_systemd.yml - vars: - program_name: "{{ almanach_collector_program_name }}" - service_name: "almanach-collector" - system_user: "{{ almanach_system_user_name }}" - system_group: "{{ almanach_system_group_name }}" - init_config_overrides: "{{ almanach_collector_init_config_overrides }}" diff --git a/tasks/almanach_init_systemd.yml b/tasks/almanach_init_systemd.yml deleted file mode 100644 index e74e8fd..0000000 --- a/tasks/almanach_init_systemd.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -# Copyright 2016, Internap 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: Place the systemd init script - template: - src: "almanach-systemd-init.j2" - dest: "/etc/systemd/system/{{ program_name }}.service" - mode: "0644" - owner: "root" - group: "root" - notify: - - Restart almanach services diff --git a/tasks/almanach_install.yml b/tasks/almanach_install.yml index b990871..bd8dc2c 100644 --- a/tasks/almanach_install.yml +++ b/tasks/almanach_install.yml @@ -13,20 +13,45 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Update APT index - apt: update_cache=yes - become: True - - name: Install apt packages - apt: + package: name: "{{ almanach_requires_apt_packages | join(' ') }}" state: present + update_cache: yes + register: install_packages + until: install_packages is success + retries: 5 + delay: 2 + +# NOTE(cloudnull): This role has no "developer_mode" as such the developer +# packages are simply installed. +- name: Install developer apt packages + package: + name: "{{ almanach_developer_mode_distro_packages }}" + state: present + update_cache: yes + register: install_packages + until: install_packages is success + retries: 5 + delay: 2 - name: Install pip packages pip: name: "{{ almanach_requires_pip_packages }}" state: present executable: pip3 + register: install_packages + until: install_packages is success + retries: 5 + delay: 2 -- name: Install Almanach - pip: name=almanach version={{ almanach_version }} virtualenv={{ almanach_app_dir }} virtualenv_python=python3 +- name: Install pip packages + pip: + name: "{{ almanach_pip_packages }}" + state: present + virtualenv: "/openstack/venvs/almanach-{{ almanach_venv_tag }}" + virtualenv_python: "python3" + register: install_packages + until: install_packages is success + retries: 5 + delay: 2 diff --git a/tasks/main.yml b/tasks/main.yml index 8064b72..8d8045f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -24,19 +24,6 @@ tags: - always -- name: Check init system - command: cat /proc/1/comm - changed_when: false - register: _pid1_name - tags: - - always - -- name: Set the name of pid1 - set_fact: - pid1_name: "{{ _pid1_name.stdout }}" - tags: - - always - - include: almanach_pre_install.yml tags: - almanach-install @@ -50,6 +37,30 @@ - almanach-install - almanach-config -- include: almanach_init.yml +- name: Run the systemd service role + include_role: + name: systemd_service + private: true + vars: + systemd_user_name: "{{ almanach_system_user_name }}" + systemd_group_name: "{{ almanach_system_group_name }}" + systemd_tempd_prefix: openstack + systemd_slice_name: almanach + systemd_lock_path: /var/lock/almanach + 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_almanach_services }}" + loop_control: + loop_var: service_var tags: - - almanach-install + - almanach-config + - systemd-service diff --git a/templates/almanach-systemd-init.j2 b/templates/almanach-systemd-init.j2 deleted file mode 100644 index 24ed015..0000000 --- a/templates/almanach-systemd-init.j2 +++ /dev/null @@ -1,31 +0,0 @@ -# {{ ansible_managed }} - -[Unit] -Description=Almanach api openstack service -After=syslog.target -After=network.target - -[Service] -Type=simple -EnvironmentFile=/etc/environment -User={{ system_user }} -Group={{ system_group }} - -ExecStart={{ almanach_app_dir }}/bin/{{ program_name }} --config-file={{ almanach_config_file }} --log-file={{ almanach_log_file }} - -# 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=almanach.slice -CPUAccounting=true -BlockIOAccounting=true -MemoryAccounting=false -TasksAccounting=true - -[Install] -WantedBy=multi-user.target diff --git a/templates/almanach.conf.j2 b/templates/almanach.conf.j2 index 6aeddca..f4fe0bd 100644 --- a/templates/almanach.conf.j2 +++ b/templates/almanach.conf.j2 @@ -1,4 +1,5 @@ [DEFAULT] +use_journal = True [api] bind_ip = {{ almanach_bind_ip }} diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..29ef4b0 --- /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_almanach_services: |- + {% set services = [] %} + {% for key, value in almanach_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/ubuntu-14.04.yml b/vars/ubuntu-14.04.yml deleted file mode 100644 index 6bee34f..0000000 --- a/vars/ubuntu-14.04.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -# Copyright 2016, Internap 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. - -## APT Cache options -cache_timeout: 600 diff --git a/vars/ubuntu-16.04.yml b/vars/ubuntu-16.04.yml index 6bee34f..035b146 100644 --- a/vars/ubuntu-16.04.yml +++ b/vars/ubuntu-16.04.yml @@ -15,3 +15,11 @@ ## APT Cache options cache_timeout: 600 + +almanach_requires_apt_packages: + - python3-pip + +almanach_developer_mode_distro_packages: + - build-essential + - libsystemd-dev + - pkg-config