From 9c8259700b19df3b2662a7ba1926959f8cab433b Mon Sep 17 00:00:00 2001 From: Przemyslaw Rzad Date: Fri, 26 Jul 2019 15:59:30 +0200 Subject: [PATCH] Add cron schedule to monitor deployment playbook (#161) * Default cron schedule * Added cron task * Docs * Overwriting log files * Removed deprecated flag * Default monitor_cron_schedule. --- deployment/CONFIGURATION.md | 1 + deployment/group_vars/dai.yml | 1 - deployment/group_vars/example.yml | 1 - deployment/group_vars/wetc.yml | 1 - deployment/hosts.yml.example | 1 + deployment/roles/monitor/defaults/main.yml | 2 ++ deployment/roles/monitor/tasks/cron.yml | 18 ++++++++++++++++++ deployment/roles/monitor/tasks/main.yml | 1 + deployment/roles/monitor/templates/.env.j2 | 1 - monitor/scripts/checkDocker.sh | 9 +++++++++ 10 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 deployment/roles/monitor/defaults/main.yml create mode 100644 deployment/roles/monitor/tasks/cron.yml create mode 100755 monitor/scripts/checkDocker.sh diff --git a/deployment/CONFIGURATION.md b/deployment/CONFIGURATION.md index 0048db81..4f02a6c1 100644 --- a/deployment/CONFIGURATION.md +++ b/deployment/CONFIGURATION.md @@ -47,6 +47,7 @@ cp hosts.yml.example hosts.yml : ansible_user: #syslog_server_port: "://:" + #monitor_cron_schedule: "*/4 * * * *" # When this parameter is set, it will overwrite default schedule for performing checks ``` The config above would install the Oracle on ``, UI on ``, and both Oracle, UI and Monitor on ``. diff --git a/deployment/group_vars/dai.yml b/deployment/group_vars/dai.yml index 0d7d3b3a..f0dfe1ad 100644 --- a/deployment/group_vars/dai.yml +++ b/deployment/group_vars/dai.yml @@ -51,4 +51,3 @@ MONITOR_FOREIGN_GAS_LIMIT: 300000 MONITOR_HOME_GAS_PRICE_FALLBACK: 0 MONITOR_FOREIGN_GAS_PRICE_FALLBACK: 10000000000 MONITOR_LEFT_TX_THRESHOLD: 100 -MONITOR_CRON_SCHEDULE: "* * * * *" diff --git a/deployment/group_vars/example.yml b/deployment/group_vars/example.yml index e32b0211..f66a35c9 100644 --- a/deployment/group_vars/example.yml +++ b/deployment/group_vars/example.yml @@ -52,4 +52,3 @@ MONITOR_FOREIGN_GAS_LIMIT: 300000 MONITOR_HOME_GAS_PRICE_FALLBACK: 1000000000 MONITOR_FOREIGN_GAS_PRICE_FALLBACK: 1000000000 MONITOR_LEFT_TX_THRESHOLD: 100 -MONITOR_CRON_SCHEDULE: "* * * * *" diff --git a/deployment/group_vars/wetc.yml b/deployment/group_vars/wetc.yml index f24c5967..1e6b1d28 100644 --- a/deployment/group_vars/wetc.yml +++ b/deployment/group_vars/wetc.yml @@ -52,4 +52,3 @@ MONITOR_FOREIGN_GAS_LIMIT: 300000 MONITOR_HOME_GAS_PRICE_FALLBACK: 15000000000 MONITOR_FOREIGN_GAS_PRICE_FALLBACK: 10000000000 MONITOR_LEFT_TX_THRESHOLD: 100 -MONITOR_CRON_SCHEDULE: "* * * * *" diff --git a/deployment/hosts.yml.example b/deployment/hosts.yml.example index ac308d63..d5f8dec7 100644 --- a/deployment/hosts.yml.example +++ b/deployment/hosts.yml.example @@ -17,3 +17,4 @@ sokol-kovan: 127.0.0.1: ansible_user: ubuntu #syslog_server_port: "://:" + #monitor_cron_schedule: "*/4 * * * *" diff --git a/deployment/roles/monitor/defaults/main.yml b/deployment/roles/monitor/defaults/main.yml new file mode 100644 index 00000000..5a56bdea --- /dev/null +++ b/deployment/roles/monitor/defaults/main.yml @@ -0,0 +1,2 @@ +--- +monitor_cron_schedule: "*/4 * * * *" diff --git a/deployment/roles/monitor/tasks/cron.yml b/deployment/roles/monitor/tasks/cron.yml new file mode 100644 index 00000000..13322ae8 --- /dev/null +++ b/deployment/roles/monitor/tasks/cron.yml @@ -0,0 +1,18 @@ +--- +- name: Parse cron schedule + set_fact: + minute: "{{ monitor_cron_schedule.split(' ')[0] }}" + hour: "{{ monitor_cron_schedule.split(' ')[1] }}" + day: "{{ monitor_cron_schedule.split(' ')[2] }}" + month: "{{ monitor_cron_schedule.split(' ')[3] }}" + weekday: "{{ monitor_cron_schedule.split(' ')[4] }}" + job: "/bin/bash -c 'cd {{ bridge_path }}/monitor/scripts; ./checkDocker.sh >cronWorker.out 2>cronWorker.err'" +- name: Add cron entry + cron: + name: "RUN_MONITOR_CHECKS" + minute: "{{ minute }}" + hour: "{{ hour }}" + day: "{{ day }}" + month: "{{ month }}" + weekday: "{{ weekday }}" + job: "{{ job }}" diff --git a/deployment/roles/monitor/tasks/main.yml b/deployment/roles/monitor/tasks/main.yml index 06af77ad..1b074a7d 100644 --- a/deployment/roles/monitor/tasks/main.yml +++ b/deployment/roles/monitor/tasks/main.yml @@ -3,3 +3,4 @@ - include_tasks: logging.yml - include_tasks: jumpbox.yml - include_tasks: servinstall.yml +- include_tasks: cron.yml diff --git a/deployment/roles/monitor/templates/.env.j2 b/deployment/roles/monitor/templates/.env.j2 index b6986660..2121911e 100644 --- a/deployment/roles/monitor/templates/.env.j2 +++ b/deployment/roles/monitor/templates/.env.j2 @@ -22,4 +22,3 @@ FOREIGN_GAS_PRICE_FALLBACK={{ MONITOR_FOREIGN_GAS_PRICE_FALLBACK }} FOREIGN_GAS_PRICE_FACTOR={{ FOREIGN_GAS_PRICE_FACTOR }} LEFT_TX_THRESHOLD={{ MONITOR_LEFT_TX_THRESHOLD }} PORT={{ MONITOR_PORT }} -CRON_SCHEDULE={{ MONITOR_CRON_SCHEDULE }} diff --git a/monitor/scripts/checkDocker.sh b/monitor/scripts/checkDocker.sh new file mode 100755 index 00000000..f44c072e --- /dev/null +++ b/monitor/scripts/checkDocker.sh @@ -0,0 +1,9 @@ +#!/bin/bash +cd $(dirname $0)/.. + +if /usr/local/bin/docker-compose ps | grep -q -i 'monitor'; then + # https://github.com/docker/compose/issues/3352 + COMPOSE_INTERACTIVE_NO_CLI=1 /usr/local/bin/docker-compose exec -T monitor /bin/bash -c 'yarn check-all' +else + echo "Monitor is not running, skipping checks." +fi