diff --git a/meta/main.yml b/meta/main.yml index 653bbdb..38cb209 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,14 +1,15 @@ --- galaxy_info: - author: flaviodsr + author: flaviodsr description: Installation and setup of sahara company: LSD/UFCG license: Apache2 - min_ansible_version: 1.6.6 + min_ansible_version: 1.9.4 platforms: - name: Ubuntu versions: - trusty + - xenial categories: - cloud - python diff --git a/tasks/main.yml b/tasks/main.yml index 0b4a373..c1a8c20 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -20,10 +20,22 @@ tags: - always +- name: Check init system + command: cat /proc/1/comm + register: _pid1_name + tags: + - always + +- name: Set the name of pid1 + set_fact: + pid1_name: "{{ _pid1_name.stdout }}" + tags: + - always + - include: sahara_pre_install.yml - include: sahara_install.yml - include: sahara_post_install.yml -- include: sahara_upstart_init.yml +- include: sahara_init.yml - include: sahara_db_setup.yml when: > diff --git a/tasks/sahara_upstart_init.yml b/tasks/sahara_init.yml similarity index 92% rename from tasks/sahara_upstart_init.yml rename to tasks/sahara_init.yml index db5bae5..eb5fc83 100644 --- a/tasks/sahara_upstart_init.yml +++ b/tasks/sahara_init.yml @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -- include: sahara_upstart_common_init.yml +- include: sahara_init_common.yml vars: program_name: "{{ sahara_api_program_name }}" service_name: "{{ sahara_service_name }}" @@ -19,7 +19,7 @@ system_group: "{{ sahara_system_group_name }}" service_home: "{{ sahara_system_user_home }}" -- include: sahara_upstart_common_init.yml +- include: sahara_init_common.yml vars: program_name: "{{ sahara_engine_program_name }}" service_name: "{{ sahara_service_name }}" diff --git a/tasks/sahara_init_common.yml b/tasks/sahara_init_common.yml new file mode 100644 index 0000000..1063147 --- /dev/null +++ b/tasks/sahara_init_common.yml @@ -0,0 +1,29 @@ +--- +# 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: sahara_init_upstart.yml + when: pid1_name == "init" + tags: + - sahara-init + +- include: sahara_init_systemd.yml + when: pid1_name == "systemd" + tags: + - sahara-init + +- name: Load service + service: + name: "{{ program_name }}" + enabled: "yes" + notify: + - Restart sahara services diff --git a/tasks/sahara_init_systemd.yml b/tasks/sahara_init_systemd.yml new file mode 100644 index 0000000..044c004 --- /dev/null +++ b/tasks/sahara_init_systemd.yml @@ -0,0 +1,49 @@ + +--- +# 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 sahara TEMP dirs + file: + path: "{{ item.path }}/{{ program_name }}" + state: directory + owner: "{{ system_user }}" + group: "{{ system_group }}" + mode: "2755" + with_items: + - { path: "/var/run" } + - { path: "/var/lock" } + +- name: Create tempfile.d entry + template: + src: "sahara-systemd-tempfiles.j2" + dest: "/etc/tmpfiles.d/sahara.conf" + mode: "0644" + owner: "root" + group: "root" + +- name: Place the systemd init script + template: + src: "sahara-systemd-init.j2" + dest: "/etc/systemd/system/{{ program_name }}.service" + mode: "0644" + owner: "root" + group: "root" + register: systemd_init + +- name: Reload the systemd daemon + command: "systemctl daemon-reload" + when: systemd_init | changed + notify: + - Restart sahara services diff --git a/tasks/sahara_upstart_common_init.yml b/tasks/sahara_init_upstart.yml similarity index 77% rename from tasks/sahara_upstart_common_init.yml rename to tasks/sahara_init_upstart.yml index e4bdf2c..944d836 100644 --- a/tasks/sahara_upstart_common_init.yml +++ b/tasks/sahara_init_upstart.yml @@ -18,27 +18,13 @@ mode: "0644" owner: "root" group: "root" + register: upstart_init notify: - Restart sahara services - tags: - - upstart-init - - sahara-init - name: Reload init scripts shell: | initctl reload-configuration + when: upstart_init | changed notify: - Restart sahara services - tags: - - upstart-init - - sahara-init - -- name: Load service - service: - name: "{{ program_name }}" - enabled: "yes" - notify: - - Restart sahara services - tags: - - upstart-init - - sahara-init diff --git a/templates/sahara-systemd-init.j2 b/templates/sahara-systemd-init.j2 new file mode 100644 index 0000000..1160fd0 --- /dev/null +++ b/templates/sahara-systemd-init.j2 @@ -0,0 +1,25 @@ +# {{ ansible_managed }} + +[Unit] +Description=sahara openstack service +After=syslog.target +After=network.target + +[Service] +Type=simple +User={{ system_user }} +Group={{ system_group }} + +{% if program_override is defined %} +ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/sahara/{{ program_name }}.log +{% else %} +ExecStart={{ sahara_bin }}/{{ program_name }} {{ program_config_options|default('') }} --log-file=/var/log/sahara/{{ program_name }}.log +{% endif %} + +# Give a reasonable amount of time for the server to start up/shut down +TimeoutSec=300 +Restart=on-failure +RestartSec=150 + +[Install] +WantedBy=multi-user.target diff --git a/templates/sahara-systemd-tempfiles.j2 b/templates/sahara-systemd-tempfiles.j2 new file mode 100644 index 0000000..b723d85 --- /dev/null +++ b/templates/sahara-systemd-tempfiles.j2 @@ -0,0 +1,4 @@ +# {{ ansible_managed }} + +D /var/lock/{{ program_name }} 2755 {{ system_user }} {{ system_group }} +D /var/run/{{ program_name }} 2755 {{ system_user }} {{ system_group }} diff --git a/vars/ubuntu-14.04.yml b/vars/ubuntu-14.04.yml index 0afde09..7920d47 100644 --- a/vars/ubuntu-14.04.yml +++ b/vars/ubuntu-14.04.yml @@ -20,4 +20,3 @@ sahara_apt_packages: - rpcbind - rsync - git - - nfs-common diff --git a/vars/ubuntu-16.04.yml b/vars/ubuntu-16.04.yml new file mode 100644 index 0000000..7920d47 --- /dev/null +++ b/vars/ubuntu-16.04.yml @@ -0,0 +1,22 @@ +# Copyright 2016, Intel Corporation. +# +# 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 + +# Common apt packages +sahara_apt_packages: + - rpcbind + - rsync + - git