From 8ddfa0b06594095c7ab07733e610756810bbd691 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 16 Jan 2025 13:45:31 -0300 Subject: [PATCH] feat: rotate csp_reports --- bin/access_logs | 13 +------------ bin/csp_reports | 4 ++++ bin/rotate_table | 17 +++++++++++++++++ monit.conf | 7 ++++++- 4 files changed, 28 insertions(+), 13 deletions(-) create mode 100755 bin/csp_reports create mode 100755 bin/rotate_table diff --git a/bin/access_logs b/bin/access_logs index cfeeb57a..aa0883fa 100755 --- a/bin/access_logs +++ b/bin/access_logs @@ -1,15 +1,4 @@ #!/bin/sh set -e -# Volcar y eliminar todos los access logs de dos días atrás -date="`dateadd today -1d`" -file="/srv/http/_storage/${date}.psql.gz" -test -n "${date}" -test ! -f "${file}" - -psql -h postgresql "${DATABASE:-sutty}" sutty < "${file}" -begin; -copy (select * from access_logs where created_at < '${date}') to stdout; -delete from access_logs where created_at < '${date}'; -commit; -SQL +`realpath $0 | xargs dirname`/rotate_table access_logs diff --git a/bin/csp_reports b/bin/csp_reports new file mode 100755 index 00000000..b8f7bcc3 --- /dev/null +++ b/bin/csp_reports @@ -0,0 +1,4 @@ +#!/bin/sh +set -e + +`realpath $0 | xargs dirname`/rotate_table csp_reports diff --git a/bin/rotate_table b/bin/rotate_table new file mode 100755 index 00000000..1b719098 --- /dev/null +++ b/bin/rotate_table @@ -0,0 +1,17 @@ +#!/bin/sh +set -e + +test -n "$1" + +# Volcar y eliminar todos los access logs de dos días atrás +date="`dateadd today -1d`" +file="/srv/_storage/$1-${date}.psql.gz" +test -n "${date}" +test ! -s "${file}" + +psql -h postgresql "${DATABASE:-sutty}" sutty < "${file}" +begin; +copy (select * from $1 where created_at < '${date}') to stdout; +delete from $1 where created_at < '${date}'; +commit; +SQL diff --git a/monit.conf b/monit.conf index 2b7e50a8..7ad96852 100644 --- a/monit.conf +++ b/monit.conf @@ -16,7 +16,12 @@ check program fediblocks check program access_logs with path "/srv/http/bin/access_logs" as uid "app" and gid "www-data" - every "0 0 * * *" + every "0 3 * * *" + if status != 0 then alert + +check program csp_reports + with path "/srv/bin/csp_reports" as uid "rails" and gid "www-data" + every "0 7 * * *" if status != 0 then alert check program stats