From 693d86e8a858bb9df97d42ac6e665210d170ad09 Mon Sep 17 00:00:00 2001 From: kiara Date: Sun, 16 Apr 2023 22:22:52 +0000 Subject: [PATCH] check-disk-space, closes #16 (#14) - moves cron jobs to code - adds job to monitor disk usage - daily job: docker prune progress: mail commando werkt voor mij ook los nog niet - thoughts? Co-authored-by: Kiara Grouwstra Reviewed-on: https://code.bij1.org/bij1/infra/pulls/14 --- .debops.cfg | 2 +- .../group_vars/debops_all_hosts/cron.yml | 25 +++++++++++++ .../debops_all_hosts/nullmailer.yml | 2 +- .../debops_service_docker_server/cron.yml | 7 ++++ .../inventory/group_vars/wordpress/cron.yml | 37 +++++++++++++++++++ ansible/inventory/host_vars/build/cron.yml | 6 +++ .../inventory/host_vars/controller/cron.yml | 7 ++++ ansible/inventory/host_vars/proxy/cron.yml | 15 ++++++++ .../inventory/host_vars/wp-staging/cron.yml | 11 ++++++ .../host_vars/wp-staging/environment.yml | 4 ++ ansible/inventory/host_vars/wp/cron.yml | 31 ++++++++++++++++ .../inventory/host_vars/wp/environment.yml | 4 ++ ansible/inventory/hosts | 4 ++ 13 files changed, 153 insertions(+), 2 deletions(-) create mode 100755 ansible/inventory/group_vars/debops_all_hosts/cron.yml create mode 100644 ansible/inventory/group_vars/debops_service_docker_server/cron.yml create mode 100755 ansible/inventory/group_vars/wordpress/cron.yml create mode 100755 ansible/inventory/host_vars/build/cron.yml create mode 100755 ansible/inventory/host_vars/controller/cron.yml create mode 100755 ansible/inventory/host_vars/proxy/cron.yml create mode 100755 ansible/inventory/host_vars/wp-staging/cron.yml create mode 100755 ansible/inventory/host_vars/wp-staging/environment.yml create mode 100755 ansible/inventory/host_vars/wp/cron.yml create mode 100755 ansible/inventory/host_vars/wp/environment.yml diff --git a/.debops.cfg b/.debops.cfg index 21b31b1..431c673 100644 --- a/.debops.cfg +++ b/.debops.cfg @@ -30,7 +30,7 @@ retry_files_enabled = false stdout_callback = yaml # Define the list of the built-in callback plugins enabled by default. -callback_whitelist = timer +callback_enabled = timer ;callback_plugins = /my/plugins/callback ;roles_path = /my/roles diff --git a/ansible/inventory/group_vars/debops_all_hosts/cron.yml b/ansible/inventory/group_vars/debops_all_hosts/cron.yml new file mode 100755 index 0000000..88392cc --- /dev/null +++ b/ansible/inventory/group_vars/debops_all_hosts/cron.yml @@ -0,0 +1,25 @@ +--- + +cron__jobs: + + 'renew-cert': + special_time: 'daily' + job: '/usr/bin/certbot renew --standalone >> /var/log/le-renew.log' + + 'check-disk-space': + special_time: 'hourly' + job: '/usr/local/lib/check-disk-space' + + custom_files: + + - dest: '/usr/local/lib/check-disk-space' + content: | + #!/bin/bash + CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g') + THRESHOLD=80 + + if [ "$CURRENT" -gt "$THRESHOLD" ] ; then + mail -s "Disk Space $(hostname).bij1.net" log@bij1.org << EOF + Used disk: $CURRENT% + EOF + fi diff --git a/ansible/inventory/group_vars/debops_all_hosts/nullmailer.yml b/ansible/inventory/group_vars/debops_all_hosts/nullmailer.yml index 7632b33..7faec31 100644 --- a/ansible/inventory/group_vars/debops_all_hosts/nullmailer.yml +++ b/ansible/inventory/group_vars/debops_all_hosts/nullmailer.yml @@ -1,6 +1,6 @@ --- -nullmailer__enabled: False +nullmailer__enabled: True nullmailer__adminaddr: log@bij1.org diff --git a/ansible/inventory/group_vars/debops_service_docker_server/cron.yml b/ansible/inventory/group_vars/debops_service_docker_server/cron.yml new file mode 100644 index 0000000..8b4a211 --- /dev/null +++ b/ansible/inventory/group_vars/debops_service_docker_server/cron.yml @@ -0,0 +1,7 @@ +--- + +cron__jobs: + + 'docker-prune': + special_time: 'daily' + job: 'docker system prune --all --force >/dev/null 2>&1' diff --git a/ansible/inventory/group_vars/wordpress/cron.yml b/ansible/inventory/group_vars/wordpress/cron.yml new file mode 100755 index 0000000..4f4c5ec --- /dev/null +++ b/ansible/inventory/group_vars/wordpress/cron.yml @@ -0,0 +1,37 @@ +--- + +cron__jobs: + + 'keepalive': + job: '/usr/local/lib/keepalive' + + custom_files: + + - dest: '/usr/local/lib/keepalive' + content: | + #!/bin/bash + + check_mariadb() + { + pidof mariadbd >/dev/null 2>&1 + } + + restart_mariadb() + { + echo "restarting mariadb"| logger -t keepalive + /etc/init.d/mariadb restart + } + + check_mariadb || restart_mariadb + + check_website() + { + curl $ALIVE_URL >/dev/null 2>&1 + } + + restart_apache() + { + systemctl restart apache2 + } + + check_website || restart_apache diff --git a/ansible/inventory/host_vars/build/cron.yml b/ansible/inventory/host_vars/build/cron.yml new file mode 100755 index 0000000..646222e --- /dev/null +++ b/ansible/inventory/host_vars/build/cron.yml @@ -0,0 +1,6 @@ +--- + +cron__jobs: + + 'persist-ci': + job: 'docker start woodpecker_woodpecker-server_1' diff --git a/ansible/inventory/host_vars/controller/cron.yml b/ansible/inventory/host_vars/controller/cron.yml new file mode 100755 index 0000000..d4abf38 --- /dev/null +++ b/ansible/inventory/host_vars/controller/cron.yml @@ -0,0 +1,7 @@ +--- + +cron__jobs: + + 'localize-trello': + special_time: 'daily' + job: '/home/kiara/localize-trello/trello.sh' diff --git a/ansible/inventory/host_vars/proxy/cron.yml b/ansible/inventory/host_vars/proxy/cron.yml new file mode 100755 index 0000000..ba12137 --- /dev/null +++ b/ansible/inventory/host_vars/proxy/cron.yml @@ -0,0 +1,15 @@ +--- + +cron__jobs: + + 'collect-stats': + job: '/usr/local/lib/collect-stats > /dev/null 2>&1' + + custom_files: + + - dest: '/usr/local/lib/collect-stats' + content: | + #!/bin/bash + echo "-----" >> /root/stats.txt + date >> stats.txt + /sbin/status >> stats.txt diff --git a/ansible/inventory/host_vars/wp-staging/cron.yml b/ansible/inventory/host_vars/wp-staging/cron.yml new file mode 100755 index 0000000..ab832ec --- /dev/null +++ b/ansible/inventory/host_vars/wp-staging/cron.yml @@ -0,0 +1,11 @@ +--- + +cron__jobs: + + 'restart-apache': + special_time: 'daily' + job: '/usr/sbin/apache2ctl graceful' + + 'restart-db': + special_time: 'daily' + job: 'systemctl restart mariadb' diff --git a/ansible/inventory/host_vars/wp-staging/environment.yml b/ansible/inventory/host_vars/wp-staging/environment.yml new file mode 100755 index 0000000..2773b27 --- /dev/null +++ b/ansible/inventory/host_vars/wp-staging/environment.yml @@ -0,0 +1,4 @@ +--- + +environment__host_variables: + - ALIVE_URL: https://wp-staging.bij1.net/ diff --git a/ansible/inventory/host_vars/wp/cron.yml b/ansible/inventory/host_vars/wp/cron.yml new file mode 100755 index 0000000..e282d08 --- /dev/null +++ b/ansible/inventory/host_vars/wp/cron.yml @@ -0,0 +1,31 @@ +--- + +cron__jobs: + + 'backup': + special_time: 'hourly' + job: '/usr/local/lib/backup-sites > /dev/null' + + custom_files: + + - dest: '/usr/local/lib/backup-sites' + content: | + #!/bin/bash + rsync -aP /etc /home/jelle/backup/ + rsync -aP /var/log /home/jelle/backup/ + apt-mark showauto > /home/jelle/backup/packages-auto.list + apt-mark showmanual > /home/jelle/backup/packages-manual.list + /usr/local/lib/backup-dbs + chown -R jelle:jelle /home/jelle/backup + + - dest: '/usr/local/lib/backup-dbs' + content: | + #!/bin/bash + databases=`mysql -u root -e "SHOW DATABASES;" | tr -d "| " | grep -v Database` + + for db in $databases; do + if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then + echo "Dumping database: $db" + mysqldump -u root --databases $db > /home/jelle/backup/dbs/$db.sql + fi + done diff --git a/ansible/inventory/host_vars/wp/environment.yml b/ansible/inventory/host_vars/wp/environment.yml new file mode 100755 index 0000000..ceb36f0 --- /dev/null +++ b/ansible/inventory/host_vars/wp/environment.yml @@ -0,0 +1,4 @@ +--- + +environment__host_variables: + - ALIVE_URL: https://shop.bij1.org/ diff --git a/ansible/inventory/hosts b/ansible/inventory/hosts index 264ab4d..9e0203e 100644 --- a/ansible/inventory/hosts +++ b/ansible/inventory/hosts @@ -94,3 +94,7 @@ crm cloud proxy +[wordpress] +wp +wp-staging +