From efa1b35719d65f6f127cdcc01833d5b40920b83a Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Wed, 14 Dec 2016 15:16:24 +0100 Subject: [PATCH] library/roles/ghn-gcore/ghn-gcore-maintenance: role that manages a cron job that restarts the gcore service. library/roles/ghn-gcore/ghn-gcoreboot: Now the start/stop scripts are added into the users's home. --- .../ghn-gcore-maintenance/defaults/main.yml | 6 ++ .../ghn-gcore-maintenance/tasks/main.yml | 33 +++++++++++ ghn-gcore/ghn-gcoreboot/defaults/main.yml | 5 ++ .../ghn-gcoreboot/files/startContainer.sh | 8 +++ .../ghn-gcoreboot/files/stopContainer.sh | 9 +++ ghn-gcore/ghn-gcoreboot/tasks/main.yml | 55 ++++++++++++------- 6 files changed, 97 insertions(+), 19 deletions(-) create mode 100644 ghn-gcore/ghn-gcore-maintenance/defaults/main.yml create mode 100644 ghn-gcore/ghn-gcore-maintenance/tasks/main.yml create mode 100644 ghn-gcore/ghn-gcoreboot/defaults/main.yml create mode 100644 ghn-gcore/ghn-gcoreboot/files/startContainer.sh create mode 100644 ghn-gcore/ghn-gcoreboot/files/stopContainer.sh diff --git a/ghn-gcore/ghn-gcore-maintenance/defaults/main.yml b/ghn-gcore/ghn-gcore-maintenance/defaults/main.yml new file mode 100644 index 00000000..123dda38 --- /dev/null +++ b/ghn-gcore/ghn-gcore-maintenance/defaults/main.yml @@ -0,0 +1,6 @@ +--- +gcore_maintenance_restart_cron: False + +gcore_maintenance_cron_users: + - { user: '{{ d4science_user }}', weekday: "0,2,4", job: "echo '`date`' >/home/{{ d4science_user }}/gcore_service_restart.log ; /home/{{ d4science_user }}/stopContainer.sh >>/home/{{ d4science_user }}/gcore_service_restart.log 2>&1 ; sleep 30 ; /home/{{ d4science_user }}/startContainer.sh >>/home/{{ d4science_user }}/gcore_service_restart.log 2>&1" } + diff --git a/ghn-gcore/ghn-gcore-maintenance/tasks/main.yml b/ghn-gcore/ghn-gcore-maintenance/tasks/main.yml new file mode 100644 index 00000000..84b701cd --- /dev/null +++ b/ghn-gcore/ghn-gcore-maintenance/tasks/main.yml @@ -0,0 +1,33 @@ +--- +- block: + - name: Install a cron job that restarts the registry gCore service + cron: name="Restart the {{ item.user }} gCore service" + minute="{{ item.minute | default(0) }}" + hour="{{ item.hour | default(3) }}" + weekday="{{ item.weekday | default('*') }}" + day="{{ item.day | default('*') }}" + user="{{ item.user }}" + job="{{ item.job }}" + disabled="{{ item.disabled | default(False) }}" + with_items: '{{ gcore_maintenance_cron_users }}' + + when: + - gcoreboot_enabled is defined and gcoreboot_enabled + - gcore_maintenance_restart_cron + tags: [ 'gcoreboot', 'gcore_cron' ] + +- block: + - name: Remove the cron job that restarts the registry gCore service + cron: name="Restart the {{ item.user }} gCore service" + minute="{{ item.minute | default(0) }}" + hour="{{ item.hour | default(3) }}" + weekday="{{ item.weekday | default('*') }}" + day="{{ item.day | default('*') }}" + user="{{ item.user }}" + job="{{ item.job }}" + disabled="{{ item.disabled | default(False) }}" + state=absent + with_items: '{{ gcore_maintenance_cron_users }}' + + when: not gcore_maintenance_restart_cron + tags: [ 'gcoreboot', 'gcore_cron' ] diff --git a/ghn-gcore/ghn-gcoreboot/defaults/main.yml b/ghn-gcore/ghn-gcoreboot/defaults/main.yml new file mode 100644 index 00000000..52349cc3 --- /dev/null +++ b/ghn-gcore/ghn-gcoreboot/defaults/main.yml @@ -0,0 +1,5 @@ +--- +gcoreboot_install: False +gcoreboot_enabled: False +gcoreboot_startcontainer: startContainer.sh +gcoreboot_stopcontainer: stopContainer.sh diff --git a/ghn-gcore/ghn-gcoreboot/files/startContainer.sh b/ghn-gcore/ghn-gcoreboot/files/startContainer.sh new file mode 100644 index 00000000..27b0c69d --- /dev/null +++ b/ghn-gcore/ghn-gcoreboot/files/startContainer.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cd $HOME +if [ -f .gcorerc ] ; then + . .gcorerc + + gcore-start-container +fi diff --git a/ghn-gcore/ghn-gcoreboot/files/stopContainer.sh b/ghn-gcore/ghn-gcoreboot/files/stopContainer.sh new file mode 100644 index 00000000..9d5ab670 --- /dev/null +++ b/ghn-gcore/ghn-gcoreboot/files/stopContainer.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +cd $HOME +if [ -f .gcorerc ] ; then + . .gcorerc + gcore-stop-container +fi + + diff --git a/ghn-gcore/ghn-gcoreboot/tasks/main.yml b/ghn-gcore/ghn-gcoreboot/tasks/main.yml index 6db433ae..4d3f1e29 100644 --- a/ghn-gcore/ghn-gcoreboot/tasks/main.yml +++ b/ghn-gcore/ghn-gcoreboot/tasks/main.yml @@ -1,23 +1,40 @@ --- -# Install the gcore boot script -- name: Install the gcore boot script - template: src=gcore.j2 dest=/etc/init.d/{{ item }} owner=root group=root mode=0755 - with_items: 'gcore' - when: - - gcoreboot_install +- block: + - name: Install the gcore boot script + template: src=gcore.j2 dest=/etc/init.d/{{ item }} owner=root group=root mode=0755 + with_items: 'gcore' + + - name: Install the start script inside the users home directory + copy: src={{ gcoreboot_startcontainer }} dest=/home/{{ item }}/{{ gcoreboot_startcontainer }} owner={{ item }} group={{ item }} mode=0755 + with_items: '{{ gcore_users }}' + + - name: Install the stop script inside the users home directory + copy: src={{ gcoreboot_stopcontainer }} dest=/home/{{ item }}/{{ gcoreboot_stopcontainer }} owner={{ item }} group={{ item }} mode=0755 + with_items: '{{ gcore_users }}' + + - name: Enable the gcore boot script + file: src=/etc/init.d/{{ item.path }} dest=/etc/{{ item.dest }} state=link + with_items: + - { path: 'gcore', dest: 'rc2.d/S95gcore' } + - { path: 'gcore', dest: 'rc3.d/S95gcore' } + - { path: 'gcore', dest: 'rc0.d/K25gcore' } + - { path: 'gcore', dest: 'rc1.d/K25gcore' } + + when: gcoreboot_install tags: [ 'gcoreboot' ] -- name: Enable the gcore boot script - file: - src=/etc/init.d/{{ item.path }} - dest=/etc/{{ item.dest }} - state=link - with_items: - - { path: 'gcore', dest: 'rc2.d/S95gcore' } - - { path: 'gcore', dest: 'rc3.d/S95gcore' } - - { path: 'gcore', dest: 'rc0.d/K25gcore.d' } - - { path: 'gcore', dest: 'rc1.d/K25gcore' } - when: - - gcoreboot_install - tags: [ 'gcoreboot' ] +- block: + - name: Remove the gcore boot script + file: dest=/etc/init.d/{{ item }} state=absent + with_items: 'gcore' + - name: disable the gcore boot script + file: dest=/etc/{{ item.dest }} state=absent + with_items: + - { path: 'gcore', dest: 'rc2.d/S95gcore' } + - { path: 'gcore', dest: 'rc3.d/S95gcore' } + - { path: 'gcore', dest: 'rc0.d/K25gcore' } + - { path: 'gcore', dest: 'rc1.d/K25gcore' } + + when: not gcoreboot_install + tags: [ 'gcoreboot' ]