DCD-386: Rework product_startup to support more systemd params and add tests for some corner cases.

This commit is contained in:
Steve Smith
2019-05-31 10:52:58 +10:00
parent 54eaed5469
commit 9e2eb50a6b
15 changed files with 281 additions and 1 deletions

View File

@@ -1,8 +1,17 @@
---
# Mostly for molecule testing, as skip-tags doesn't work with handlers.
atl_startup_enable: true
atl_startup_restart: true
atl_startup_script_map:
jira: "start-jira.sh"
confluence: "start-confluence.sh"
stash: "start-bitbucket.sh"
atl_startup_exec_path: "{{ atl_product_installation_current }}/bin/{{ atl_startup_script_map[atl_product_family] }}"
atl_startup_exec_options: ["-fg"]
atl_startup_systemd_params: []
atl_systemd_service_name: "{{ atl_product_edition }}.service"

View File

@@ -4,6 +4,9 @@
service:
name: "{{ atl_systemd_service_name }}"
state: restarted
when: atl_startup_restart
- name: Enable Product
command: systemctl enable "{{ atl_systemd_service_name }}"
when: atl_startup_enable

View File

@@ -0,0 +1,14 @@
# Molecule managed
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi

View File

@@ -0,0 +1,36 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: amazon_linux2
image: amazonlinux:2
groups:
- aws_node_local
ulimits:
- nofile:262144:262144
- name: ubuntu_lts
image: ubuntu:bionic
groups:
- aws_node_local
ulimits:
- nofile:262144:262144
provisioner:
name: ansible
options:
skip-tags: runtime_pkg
lint:
name: ansible-lint
options:
x: ["701"]
inventory:
links:
group_vars: ../../../../group_vars/
verifier:
name: testinfra
lint:
name: flake8
enabled: false

View File

@@ -0,0 +1,28 @@
---
- name: Converge
hosts: all
vars:
atl_product_user: "bitbucket"
atl_product_family: "stash"
atl_product_edition: "bitbucket"
atl_startup_systemd_params:
- "UMask=0027"
- "LimitNOFILE=4096"
- "Environment=BITBUCKET_HOME={{ atl_product_home_shared }}"
atl_startup_exec_options:
- "-fg"
- "--no-search"
atl_startup_enable: false
atl_startup_restart: false
pre_tasks:
- name: Create systemd dir if necessary
file:
path: '/etc/systemd/system/'
state: directory
roles:
- role: product_startup

View File

@@ -0,0 +1,14 @@
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_service_file(host):
f = host.file('/etc/systemd/system/bitbucket.service')
assert f.contains("^ExecStart=/opt/atlassian/bitbucket/current/bin/start-bitbucket.sh -fg --no-search$")
assert f.contains("^UMask=0027$")
assert f.contains("^LimitNOFILE=4096$")
assert f.contains("^Environment=BITBUCKET_HOME=/media/atl/bitbucket/shared$")

View File

@@ -0,0 +1,14 @@
# Molecule managed
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi

View File

@@ -0,0 +1,36 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: amazon_linux2
image: amazonlinux:2
groups:
- aws_node_local
ulimits:
- nofile:262144:262144
- name: ubuntu_lts
image: ubuntu:bionic
groups:
- aws_node_local
ulimits:
- nofile:262144:262144
provisioner:
name: ansible
options:
skip-tags: runtime_pkg
lint:
name: ansible-lint
options:
x: ["701"]
inventory:
links:
group_vars: ../../../../group_vars/
verifier:
name: testinfra
lint:
name: flake8
enabled: false

View File

@@ -0,0 +1,19 @@
---
- name: Converge
hosts: all
vars:
atl_product_user: "jira"
atl_product_family: "jira"
atl_product_edition: "jira-software"
atl_startup_enable: false
atl_startup_restart: false
pre_tasks:
- name: Create systemd dir if necessary
file:
path: '/etc/systemd/system/'
state: directory
roles:
- role: product_startup

View File

@@ -0,0 +1,11 @@
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_service_file(host):
f = host.file('/etc/systemd/system/jira-software.service')
assert f.contains("^ExecStart=/opt/atlassian/jira-software/current/bin/start-jira.sh -fg$")

View File

@@ -0,0 +1,14 @@
# Molecule managed
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi

View File

@@ -0,0 +1,36 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: amazon_linux2
image: amazonlinux:2
groups:
- aws_node_local
ulimits:
- nofile:262144:262144
- name: ubuntu_lts
image: ubuntu:bionic
groups:
- aws_node_local
ulimits:
- nofile:262144:262144
provisioner:
name: ansible
options:
skip-tags: runtime_pkg
lint:
name: ansible-lint
options:
x: ["701"]
inventory:
links:
group_vars: ../../../../group_vars/
verifier:
name: testinfra
lint:
name: flake8
enabled: false

View File

@@ -0,0 +1,27 @@
---
- name: Converge
hosts: all
vars:
atl_product_user: "confluence"
atl_product_family: "confluence"
atl_product_edition: "confluence"
atl_startup_systemd_params:
- "EnvironmentFile=/etc/atl"
- "EnvironmentFile=/etc/atl.synchrony"
- "WorkingDirectory={{ atl_product_installation_current }}/logs/"
atl_startup_exec_options: []
atl_startup_exec_path: "{{ atl_installation_base }}/bin/start-synchrony"
atl_systemd_service_name: "synchrony.service"
atl_startup_enable: false
atl_startup_restart: false
pre_tasks:
- name: Create systemd dir if necessary
file:
path: '/etc/systemd/system/'
state: directory
roles:
- role: product_startup

View File

@@ -0,0 +1,14 @@
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_service_file(host):
f = host.file('/etc/systemd/system/synchrony.service')
assert f.contains("^ExecStart=/opt/atlassian/bin/start-synchrony$")
assert f.contains("^EnvironmentFile=/etc/atl$")
assert f.contains("^EnvironmentFile=/etc/atl.synchrony$")
assert f.contains("^WorkingDirectory=/opt/atlassian/confluence/current/logs/$")

View File

@@ -6,7 +6,12 @@ After=network-online.target
User={{ atl_product_user }}
Group={{ atl_product_user }}
ExecStart={{ atl_product_installation_current }}/bin/{{ atl_startup_script_map[atl_product_family] }} -fg
{% for p in atl_startup_systemd_params -%}
{{ p }}
{% endfor %}
ExecStart={{ atl_startup_exec_path }}{% for c in atl_startup_exec_options %} {{ c }}{% endfor %}
Restart=on-failure
[Install]