From d7f83b6ec27252f542a0f0761719221eacbaa738 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin <4533074+alexAubin@users.noreply.github.com> Date: Sun, 12 May 2024 17:43:07 +0200 Subject: [PATCH] Replace rebuild.sh / sourcesautoupdate.sh with a maintenance.sh to properly update cron job and auto-restart services when updating their code (#2323) * Replace rebuild.sh / sourcesautoupdate.sh with a maintenance.sh to properly update cron job and auto-restart services when updating their code * Mistakenly change the cron job periods * Apply suggestions from code review @_@ --- cron | 12 +++++-- maintenance.sh | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 maintenance.sh diff --git a/cron b/cron index 631a36f..92d344f 100644 --- a/cron +++ b/cron @@ -1,8 +1,14 @@ # Every 4 hours -0 */4 * * * root /bin/bash __BASEDIR__/rebuild.sh +0 */4 * * * root /bin/bash __BASEDIR__/maintenance.sh rebuild_catalog # Everyday at 01:30 UTC -30 1 * * * root /bin/bash __BASEDIR__/sourcesautoupdate.sh +30 1 * * * root /bin/bash __BASEDIR__/maintenance.sh autoupdate_app_sources # Every friday at 6 PM UTC -0 17 * * 5 root /usr/bin/python3 __BASEDIR__/tools/update_app_levels/update_app_levels.py +0 17 * * 5 root /bin/bash __BASEDIR__/maintenance.sh update_app_levels + +# Every 6 hours +0 */6 * * * root /bin/bash __BASEDIR__/maintenance.sh fetch_main_dashboard + +# Every day at 2AM +0 2 * * * root /bin/bash __BASEDIR__/maintenance.sh fetch_level_history diff --git a/maintenance.sh b/maintenance.sh new file mode 100644 index 0000000..bea127a --- /dev/null +++ b/maintenance.sh @@ -0,0 +1,98 @@ +#!/usr/bin/env bash + +workdir=$(realpath $(dirname "$0")) +cd $workdir + +function git_pull_and_update_cron_and_restart_services_if_needed() +{ + git pull &>/dev/null + + # Cron + cat cron | sed "s@__BASEDIR__@$workdir@g" > /etc/cron.d/app_list + + # App store + chown -R appstore store + pushd store >/dev/null + modified_after_service_start="$(find *.py translations/ templates/ assets/ -newermt "$(systemctl show --property=ActiveEnterTimestamp appstore | cut -d= -f2 | cut -d' ' -f2-3)-1")" + if [ -n "$modified_after_service_start" ] + then + pushd assets >/dev/null + ./tailwindcss-linux-x64 --input tailwind-local.css --output tailwind.css --minify + popd >/dev/null + systemctl restart appstore + sleep 3 + fi + popd >/dev/null + + systemctl --quiet is-active appstore || sendxmpppy "[appstore] Uhoh, failed to (re)start the appstore service?" + + # App generator + chown -R appgenerator tools/app_generator + pushd tools/app_generator >/dev/null + modified_after_service_start="$(find *.py translations/ templates/ static/ -newermt "$(systemctl show --property=ActiveEnterTimestamp appgenerator | cut -d= -f2 | cut -d' ' -f2-3)-1")" + if [ -n "$modified_after_service_start" ] + then + pushd assets >/dev/null + ./tailwindcss-linux-x64 --input tailwind-local.css --output tailwind.css --minify + popd >/dev/null + systemctl restart appgenerator + sleep 3 + fi + popd >/dev/null + + systemctl --quiet is-active appgenerator || sendxmpppy "[appgenerator] Uhoh, failed to (re)start the appgenerator service?" + + # Autoreadme + pushd tools/readme_generator >/dev/null + modified_after_service_start="$(find *.py translations/ templates/ -newermt "$(systemctl show --property=ActiveEnterTimestamp autoreadme | cut -d= -f2 | cut -d' ' -f2-3)-1")" + if [ -n "$modified_after_service_start" ] + then + systemctl restart autoreadme + sleep 3 + fi + popd >/dev/null + + systemctl --quiet is-active autoreadme || sendxmpppy "[autoreadme] Uhoh, failed to (re)start the autoreadme service?" +} + +function rebuild_catalog() +{ + log=$workdir/app_list_auto_update.log + date >> $log + git_pull_and_update_cron_and_restart_services_if_needed + ./tools/list_builder.py &>> $log || sendxmpppy "[listbuilder] Rebuilding the application list failed miserably" +} + +function autoupdate_app_sources() +{ + log=$workdir/app_sources_auto_update.log + date >> $log + git_pull_and_update_cron_and_restart_services_if_needed + python3 tools/autoupdate_app_sources/autoupdate_app_sources.py \ + --edit --commit --pr --paste -j1 \ + &> $log || sendxmpppy "[appsourcesautoupdate] App sources auto-update failed miserably" +} + +function update_app_levels() +{ + pushd tools/update_app_levels >/dev/null + python3 update_app_levels.py + popd >/dev/null +} + +function fetch_main_dashboard() +{ + pushd store >/dev/null + venv/bin/python3 fetch_main_dashboard.py + popd >/dev/null +} + + +function fetch_level_history() +{ + pushd store >/dev/null + venv/bin/python3 fetch_level_history.py + popd >/dev/null +} + +$1