From 8a0ed8264d1b884c46dfa1fb5a5862bac6e1aceb Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 23 Feb 2023 20:28:43 +0100 Subject: [PATCH] Set up regular microblog.pub DB pruning. --- .../etc/systemd/system/microblogpub_prune.service | 9 +++++++++ .../etc/systemd/system/microblogpub_prune.timer | 9 +++++++++ bullseye/other_files/prune_microblog.sh | 10 ++++++++++ bullseye/setup_scripts/setup_microblogpub.sh | 5 +++++ 4 files changed, 33 insertions(+) create mode 100644 bullseye/etc_files/microblogpub/etc/systemd/system/microblogpub_prune.service create mode 100644 bullseye/etc_files/microblogpub/etc/systemd/system/microblogpub_prune.timer create mode 100644 bullseye/other_files/prune_microblog.sh diff --git a/bullseye/etc_files/microblogpub/etc/systemd/system/microblogpub_prune.service b/bullseye/etc_files/microblogpub/etc/systemd/system/microblogpub_prune.service new file mode 100644 index 0000000..9004cc5 --- /dev/null +++ b/bullseye/etc_files/microblogpub/etc/systemd/system/microblogpub_prune.service @@ -0,0 +1,9 @@ +[Unit] +Description=microblog.pub pruning + +[Service] +Type=simple +ExecStart=/bin/sh -c '.prune.sh' + +[Install] +WantedBy=multi-user.target diff --git a/bullseye/etc_files/microblogpub/etc/systemd/system/microblogpub_prune.timer b/bullseye/etc_files/microblogpub/etc/systemd/system/microblogpub_prune.timer new file mode 100644 index 0000000..d954385 --- /dev/null +++ b/bullseye/etc_files/microblogpub/etc/systemd/system/microblogpub_prune.timer @@ -0,0 +1,9 @@ +[Unit] +Description=schedule microblog.pub pruning + +[Timer] +Unit=reboot.service +OnCalendar=*-*-* 7:00:00 + +[Install] +WantedBy=timers.target diff --git a/bullseye/other_files/prune_microblog.sh b/bullseye/other_files/prune_microblog.sh new file mode 100644 index 0000000..8cfc385 --- /dev/null +++ b/bullseye/other_files/prune_microblog.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -e +set -x +service microblogpub stop +microblogdir=/home/plom/testing.microblog.pub +cd "${microblogdir}" +cp -r data/microblogpub.db data/microblogpub.db.bak.$(date +%a) +su -lc "cd ${microblogdir} && poetry run inv prune-old-data" - plom +service microblogpub start +echo "last microblog pruning at $(date)" >> /home/plom/prune_log.txt diff --git a/bullseye/setup_scripts/setup_microblogpub.sh b/bullseye/setup_scripts/setup_microblogpub.sh index ce0d7d1..d0f68c9 100755 --- a/bullseye/setup_scripts/setup_microblogpub.sh +++ b/bullseye/setup_scripts/setup_microblogpub.sh @@ -51,3 +51,8 @@ service microblogpub start sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/nginx/sites-available/microblogpub.nginx ln -s /etc/nginx/sites-available/microblogpub.nginx /etc/nginx/sites-enabled/microblogpub.nginx service nginx restart + +# Setup regular DB pruning +cp "${config_tree_prefix}/other_files/prune_microblog.sh" /home/plom/ +systemctl enable microblogpub_prune.timer +systemctl start microblogpub_prune.timer -- 2.30.2