diff --git a/roles/product_startup/defaults/main.yml b/roles/product_startup/defaults/main.yml index dd0baa5..dee6aae 100644 --- a/roles/product_startup/defaults/main.yml +++ b/roles/product_startup/defaults/main.yml @@ -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" diff --git a/roles/product_startup/handlers/main.yml b/roles/product_startup/handlers/main.yml index 7df4867..f107732 100644 --- a/roles/product_startup/handlers/main.yml +++ b/roles/product_startup/handlers/main.yml @@ -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 + diff --git a/roles/product_startup/molecule/bitbucket/Dockerfile.j2 b/roles/product_startup/molecule/bitbucket/Dockerfile.j2 new file mode 100644 index 0000000..e6aa95d --- /dev/null +++ b/roles/product_startup/molecule/bitbucket/Dockerfile.j2 @@ -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 diff --git a/roles/product_startup/molecule/bitbucket/molecule.yml b/roles/product_startup/molecule/bitbucket/molecule.yml new file mode 100644 index 0000000..7f082f6 --- /dev/null +++ b/roles/product_startup/molecule/bitbucket/molecule.yml @@ -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 diff --git a/roles/product_startup/molecule/bitbucket/playbook.yml b/roles/product_startup/molecule/bitbucket/playbook.yml new file mode 100644 index 0000000..84d25ae --- /dev/null +++ b/roles/product_startup/molecule/bitbucket/playbook.yml @@ -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 diff --git a/roles/product_startup/molecule/bitbucket/tests/test_default.py b/roles/product_startup/molecule/bitbucket/tests/test_default.py new file mode 100644 index 0000000..1f9aeb0 --- /dev/null +++ b/roles/product_startup/molecule/bitbucket/tests/test_default.py @@ -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$") diff --git a/roles/product_startup/molecule/default/Dockerfile.j2 b/roles/product_startup/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..e6aa95d --- /dev/null +++ b/roles/product_startup/molecule/default/Dockerfile.j2 @@ -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 diff --git a/roles/product_startup/molecule/default/molecule.yml b/roles/product_startup/molecule/default/molecule.yml new file mode 100644 index 0000000..7f082f6 --- /dev/null +++ b/roles/product_startup/molecule/default/molecule.yml @@ -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 diff --git a/roles/product_startup/molecule/default/playbook.yml b/roles/product_startup/molecule/default/playbook.yml new file mode 100644 index 0000000..9c31c46 --- /dev/null +++ b/roles/product_startup/molecule/default/playbook.yml @@ -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 diff --git a/roles/product_startup/molecule/default/tests/test_default.py b/roles/product_startup/molecule/default/tests/test_default.py new file mode 100644 index 0000000..f01d546 --- /dev/null +++ b/roles/product_startup/molecule/default/tests/test_default.py @@ -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$") diff --git a/roles/product_startup/molecule/synchrony/Dockerfile.j2 b/roles/product_startup/molecule/synchrony/Dockerfile.j2 new file mode 100644 index 0000000..e6aa95d --- /dev/null +++ b/roles/product_startup/molecule/synchrony/Dockerfile.j2 @@ -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 diff --git a/roles/product_startup/molecule/synchrony/molecule.yml b/roles/product_startup/molecule/synchrony/molecule.yml new file mode 100644 index 0000000..7f082f6 --- /dev/null +++ b/roles/product_startup/molecule/synchrony/molecule.yml @@ -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 diff --git a/roles/product_startup/molecule/synchrony/playbook.yml b/roles/product_startup/molecule/synchrony/playbook.yml new file mode 100644 index 0000000..d848712 --- /dev/null +++ b/roles/product_startup/molecule/synchrony/playbook.yml @@ -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 diff --git a/roles/product_startup/molecule/synchrony/tests/test_default.py b/roles/product_startup/molecule/synchrony/tests/test_default.py new file mode 100644 index 0000000..447af2e --- /dev/null +++ b/roles/product_startup/molecule/synchrony/tests/test_default.py @@ -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/$") diff --git a/roles/product_startup/templates/product.service.j2 b/roles/product_startup/templates/product.service.j2 index c64de87..6b5077f 100644 --- a/roles/product_startup/templates/product.service.j2 +++ b/roles/product_startup/templates/product.service.j2 @@ -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]