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 @_@
This commit is contained in:
parent
9363d4e086
commit
d7f83b6ec2
2 changed files with 107 additions and 3 deletions
12
cron
12
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
|
||||
|
|
98
maintenance.sh
Normal file
98
maintenance.sh
Normal file
|
@ -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
|
Loading…
Reference in a new issue