From b37e172a44261cca9e3b44b3b23fbd134aaab34e Mon Sep 17 00:00:00 2001 From: Carlos Konstanski Date: Tue, 6 Mar 2018 19:50:01 -0700 Subject: Support pure systemd hosts Issue: IS-75 --- salt/openbook/ansible/files/openbook.yaml | 44 +++++++++++----------- .../ansible/files/stop_start_openbook.yaml | 27 +++++++++++-- salt/openbook/ci/files/openbook.gentoo | 31 --------------- .../openbook/ci/files/openbook.gentoo.openrc.debug | 17 +++++++++ .../openbook/ci/files/openbook.gentoo.openrc.start | 16 ++++++++ .../ci/files/openbook.gentoo.systemd.debug | 10 +++++ .../ci/files/openbook.gentoo.systemd.start | 10 +++++ salt/openbook/ci/files/openbook.redhat | 32 ---------------- salt/openbook/ci/files/openbook.redhat.debug | 26 +++++++++++++ salt/openbook/ci/files/openbook.redhat.start | 26 +++++++++++++ salt/openbook/ci/files/openbook.ubuntu | 28 -------------- salt/openbook/ci/files/openbook.ubuntu.debug | 22 +++++++++++ salt/openbook/ci/files/openbook.ubuntu.start | 22 +++++++++++ 13 files changed, 196 insertions(+), 115 deletions(-) delete mode 100644 salt/openbook/ci/files/openbook.gentoo create mode 100644 salt/openbook/ci/files/openbook.gentoo.openrc.debug create mode 100644 salt/openbook/ci/files/openbook.gentoo.openrc.start create mode 100644 salt/openbook/ci/files/openbook.gentoo.systemd.debug create mode 100644 salt/openbook/ci/files/openbook.gentoo.systemd.start delete mode 100644 salt/openbook/ci/files/openbook.redhat create mode 100644 salt/openbook/ci/files/openbook.redhat.debug create mode 100644 salt/openbook/ci/files/openbook.redhat.start delete mode 100644 salt/openbook/ci/files/openbook.ubuntu create mode 100644 salt/openbook/ci/files/openbook.ubuntu.debug create mode 100644 salt/openbook/ci/files/openbook.ubuntu.start (limited to 'salt/openbook') diff --git a/salt/openbook/ansible/files/openbook.yaml b/salt/openbook/ansible/files/openbook.yaml index a2d9688..1614194 100644 --- a/salt/openbook/ansible/files/openbook.yaml +++ b/salt/openbook/ansible/files/openbook.yaml @@ -117,7 +117,8 @@ owner: root group: root with_items: - - { src: ci/{{ pillar["ci"]["files"]["openbook_ubuntu"]["path"] }}/{{ pillar["ci"]["files"]["openbook_ubuntu"]["name"] }}, dest: /etc/init.d/openbook, mode: "0755" } + - { src: ci/{{ pillar["ci"]["files"]["openbook_ubuntu_start"]["path"] }}/{{ pillar["ci"]["files"]["openbook_ubuntu_start"]["name"] }}, dest: /etc/init.d/openbook, mode: "0755" } + - { src: ci/{{ pillar["ci"]["files"]["openbook_ubuntu_debug"]["path"] }}/{{ pillar["ci"]["files"]["openbook_ubuntu_debug"]["name"] }}, dest: /etc/init.d/openbook-debug, mode: "0755" } when: ansible_distribution == "Ubuntu" - name: "Create Openbook init script: Redhat" @@ -128,7 +129,8 @@ owner: root group: root with_items: - - { src: ci/{{ pillar["ci"]["files"]["openbook_redhat"]["path"] }}/{{ pillar["ci"]["files"]["openbook_redhat"]["name"] }}, dest: /etc/init.d/openbook, mode: "0755" } + - { src: ci/{{ pillar["ci"]["files"]["openbook_redhat_start"]["path"] }}/{{ pillar["ci"]["files"]["openbook_redhat_start"]["name"] }}, dest: /etc/init.d/openbook, mode: "0755" } + - { src: ci/{{ pillar["ci"]["files"]["openbook_redhat_debug"]["path"] }}/{{ pillar["ci"]["files"]["openbook_redhat_debug"]["name"] }}, dest: /etc/init.d/openbook-debug, mode: "0755" } when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS" - name: "Create Openbook init script: Gentoo" @@ -139,12 +141,25 @@ owner: root group: root with_items: - - { src: ci/{{ pillar["ci"]["files"]["openbook_gentoo"]["path"] }}/{{ pillar["ci"]["files"]["openbook_gentoo"]["name"] }}, dest: /etc/init.d/openbook, mode: "0755" } - when: ansible_distribution == "Gentoo" + - { src: ci/{{ pillar["ci"]["files"]["openbook_gentoo_openrc_start"]["path"] }}/{{ pillar["ci"]["files"]["openbook_gentoo_openrc_start"]["name"] }}, dest: /etc/init.d/openbook, mode: "0755" } + - { src: ci/{{ pillar["ci"]["files"]["openbook_gentoo_openrc_debug"]["path"] }}/{{ pillar["ci"]["files"]["openbook_gentoo_openrc_debug"]["name"] }}, dest: /etc/init.d/openbook-debug, mode: "0755" } + when: ansible_distribution == "Gentoo" and ansible_service_mgr == "openrc" + + - name: "Create Openbook systemd scripts: Gentoo" + template: + src: "../templates/{% raw %}{{ item.src }}{% endraw %}" + dest: "{% raw %}{{ item.dest }}{% endraw %}" + mode: "{% raw %}{{ item.mode }}{% endraw %}" + owner: root + group: root + with_items: + - { src: ci/{{ pillar["ci"]["files"]["openbook_gentoo_systemd_start"]["path"] }}/{{ pillar["ci"]["files"]["openbook_gentoo_systemd_start"]["name"] }}, dest: /etc/systemctl/system/openbook.service, mode: "0644" } + - { src: ci/{{ pillar["ci"]["files"]["openbook_gentoo_systemd_debug"]["path"] }}/{{ pillar["ci"]["files"]["openbook_gentoo_systemd_debug"]["name"] }}, dest: /etc/systemctl/system/openbook-debug.service, mode: "0644" } + when: ansible_distribution == "Gentoo" and ansible_service_mgr == "systemd" - name: "Add service script to systemd" shell: systemctl enable openbook - when: ansible_distribution == "Ubuntu" or ansible_distribution == "RedHat" or ansible_distribution == "CentOS" + when: ansible_distribution == "Ubuntu" or ansible_distribution == "RedHat" or ansible_distribution == "CentOS" or (ansible_distribution == "Gentoo" and ansible_service_mgr == "systemd") - name: "Enable openbook service" service: @@ -165,16 +180,7 @@ when: openbook_install_database|string() == "True" - name: "Stop Openbook" - hosts: "{% raw %}{{ groups['target']|sort(reverse=True) }}{% endraw %}" - serial: 1 - tasks: - - name: "Stop Openbook" - shell: | - /etc/init.d/openbook stop - for cont in $(docker ps | grep -v 'COMMAND' | awk '{print $1}'); do - docker stop ${cont} - done - docker container prune -f + include: stop_start_openbook.yaml action=stop - name: "Install Openbook" hosts: target @@ -216,9 +222,5 @@ executable: /bin/bash - name: "Start Openbook" - hosts: "{% raw %}{{ groups['target']|sort }}{% endraw %}" - serial: 1 - tasks: - - name: "Start Openbook" - shell: /etc/init.d/openbook start - when: openbook_start_app == True + include: stop_start_openbook.yaml action=start + when: openbook_start_app == True diff --git a/salt/openbook/ansible/files/stop_start_openbook.yaml b/salt/openbook/ansible/files/stop_start_openbook.yaml index c34a7ff..abe4be4 100644 --- a/salt/openbook/ansible/files/stop_start_openbook.yaml +++ b/salt/openbook/ansible/files/stop_start_openbook.yaml @@ -12,12 +12,23 @@ serial: 1 tasks: - name: "Stop Openbook" + service: + name: "{{ item.name }}" + state: stopped + runlevel: "{{ item.runlevel }}" + with_items: + - { name: openbook, runlevel: default } + - { name: openbook-debug, runlevel: default } + ignore_errors: True + when: action == "stop" + + - name: "Delete Openbook containers" shell: | - /etc/init.d/openbook stop for cont in $(docker ps | grep -v 'COMMAND' | awk '{print $1}'); do docker stop ${cont} done docker container prune -f + ignore_errors: True when: action in ["stop", "restart"] - name: "Start Openbook" @@ -25,9 +36,19 @@ serial: 1 tasks: - name: "Start Openbook" - shell: /etc/init.d/openbook start + service: + name: "{{ item.name }}" + state: started + runlevel: "{{ item.runlevel }}" + with_items: + - { name: openbook, runlevel: default } when: action in ["start", "restart"] and extra_args != "debug" - name: "Start Openbook in debug mode" - shell: /etc/init.d/openbook debug + service: + name: "{{ item.name }}" + state: started + runlevel: "{{ item.runlevel }}" + with_items: + - { name: openbook-debug, runlevel: default } when: action in ["start", "restart"] and extra_args == "debug" diff --git a/salt/openbook/ci/files/openbook.gentoo b/salt/openbook/ci/files/openbook.gentoo deleted file mode 100644 index 62dd27a..0000000 --- a/salt/openbook/ci/files/openbook.gentoo +++ /dev/null @@ -1,31 +0,0 @@ -#!/sbin/openrc-run - -extra_commands="debug test_database" - -depend() { - need docker -} - -start() { - ebegin "Starting Openbook" - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} start - eend $? -} - -debug() { - ebegin "Starting Openbook in debug mode" - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} debug - eend $? -} - -stop() { - ebegin "Stopping Openbook" - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} stop - eend $? -} - -test_database() { - ebegin "Testing database" - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} test_database - eend $? -} diff --git a/salt/openbook/ci/files/openbook.gentoo.openrc.debug b/salt/openbook/ci/files/openbook.gentoo.openrc.debug new file mode 100644 index 0000000..75d7bc9 --- /dev/null +++ b/salt/openbook/ci/files/openbook.gentoo.openrc.debug @@ -0,0 +1,17 @@ +#!/sbin/openrc-run + +depend() { + need docker +} + +start() { + ebegin "Starting Openbook" + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} debug + eend $? +} + +stop() { + ebegin "Stopping Openbook" + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} stop + eend $? +} diff --git a/salt/openbook/ci/files/openbook.gentoo.openrc.start b/salt/openbook/ci/files/openbook.gentoo.openrc.start new file mode 100644 index 0000000..e2ee244 --- /dev/null +++ b/salt/openbook/ci/files/openbook.gentoo.openrc.start @@ -0,0 +1,16 @@ +#!/sbin/openrc-run + +depend() { + need docker +} + +start() { + ebegin "Starting Openbook" + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} start + eend $? +} +stop() { + ebegin "Stopping Openbook" + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} stop + eend $? +} diff --git a/salt/openbook/ci/files/openbook.gentoo.systemd.debug b/salt/openbook/ci/files/openbook.gentoo.systemd.debug new file mode 100644 index 0000000..69642b7 --- /dev/null +++ b/salt/openbook/ci/files/openbook.gentoo.systemd.debug @@ -0,0 +1,10 @@ +[Unit] +Description=Openbook +After=network.target nss-lookup.target docker.target + +[Service] +Type=forking +ExecStart={{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} debug + +[Install] +WantedBy=multi-user.target diff --git a/salt/openbook/ci/files/openbook.gentoo.systemd.start b/salt/openbook/ci/files/openbook.gentoo.systemd.start new file mode 100644 index 0000000..35f067a --- /dev/null +++ b/salt/openbook/ci/files/openbook.gentoo.systemd.start @@ -0,0 +1,10 @@ +[Unit] +Description=Openbook +After=network.target nss-lookup.target docker.target + +[Service] +Type=forking +ExecStart={{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} start + +[Install] +WantedBy=multi-user.target diff --git a/salt/openbook/ci/files/openbook.redhat b/salt/openbook/ci/files/openbook.redhat deleted file mode 100644 index 5f3f934..0000000 --- a/salt/openbook/ci/files/openbook.redhat +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -# openbook -# -# chkconfig: 2345 10 90 -# description: Manage the Openbook application -# -### BEGIN INIT INFO -# Provides: openbook -# Required-Start: docker -# Required-Stop: docker -# Short-Description: Bring up/down networking -# Description: Manage the Openbook application -### END INIT INFO - -case $1 in - start*) - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} start - ;; - debug*) - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} debug - ;; - stop*) - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} stop - ;; - test_database*) - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} test_database - ;; - *) - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} help - ;; -esac diff --git a/salt/openbook/ci/files/openbook.redhat.debug b/salt/openbook/ci/files/openbook.redhat.debug new file mode 100644 index 0000000..b91bd94 --- /dev/null +++ b/salt/openbook/ci/files/openbook.redhat.debug @@ -0,0 +1,26 @@ +#!/bin/bash + +# openbook +# +# chkconfig: 2345 10 90 +# description: Manage the Openbook application +# +### BEGIN INIT INFO +# Provides: openbook +# Required-Start: docker +# Required-Stop: docker +# Short-Description: Bring up/down networking +# Description: Manage the Openbook application +### END INIT INFO + +case $1 in + start*) + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} debug + ;; + stop*) + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} stop + ;; + *) + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} help + ;; +esac diff --git a/salt/openbook/ci/files/openbook.redhat.start b/salt/openbook/ci/files/openbook.redhat.start new file mode 100644 index 0000000..d4e4937 --- /dev/null +++ b/salt/openbook/ci/files/openbook.redhat.start @@ -0,0 +1,26 @@ +#!/bin/bash + +# openbook +# +# chkconfig: 2345 10 90 +# description: Manage the Openbook application +# +### BEGIN INIT INFO +# Provides: openbook +# Required-Start: docker +# Required-Stop: docker +# Short-Description: Bring up/down networking +# Description: Manage the Openbook application +### END INIT INFO + +case $1 in + start*) + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} start + ;; + stop*) + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} stop + ;; + *) + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} help + ;; +esac diff --git a/salt/openbook/ci/files/openbook.ubuntu b/salt/openbook/ci/files/openbook.ubuntu deleted file mode 100644 index 6c50c76..0000000 --- a/salt/openbook/ci/files/openbook.ubuntu +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -### BEGIN INIT INFO -# Provides: openbook -# Required-Start: docker -# Required-Stop: docker -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Manage the Openbook application -### END INIT INFO - -case $1 in - start*) - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} start - ;; - debug*) - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} debug - ;; - stop*) - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} stop - ;; - test_database*) - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} test_database - ;; - *) - {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} help - ;; -esac diff --git a/salt/openbook/ci/files/openbook.ubuntu.debug b/salt/openbook/ci/files/openbook.ubuntu.debug new file mode 100644 index 0000000..b99726f --- /dev/null +++ b/salt/openbook/ci/files/openbook.ubuntu.debug @@ -0,0 +1,22 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: openbook +# Required-Start: docker +# Required-Stop: docker +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Manage the Openbook application +### END INIT INFO + +case $1 in + start*) + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} debug + ;; + stop*) + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} stop + ;; + *) + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} help + ;; +esac diff --git a/salt/openbook/ci/files/openbook.ubuntu.start b/salt/openbook/ci/files/openbook.ubuntu.start new file mode 100644 index 0000000..51141e5 --- /dev/null +++ b/salt/openbook/ci/files/openbook.ubuntu.start @@ -0,0 +1,22 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: openbook +# Required-Start: docker +# Required-Stop: docker +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Manage the Openbook application +### END INIT INFO + +case $1 in + start*) + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} start + ;; + stop*) + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} stop + ;; + *) + {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} help + ;; +esac -- cgit v1.3