feat: automate production maintenance
This commit is contained in:
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
repo=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
|
||||
cd "$repo"
|
||||
env_file=${COMPOSE_ENV_FILE:-.env.production}
|
||||
if [ ! -r "$env_file" ]; then
|
||||
echo "Production env file is not readable: $env_file" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
backup_root=${BACKUP_ROOT:-$(sed -n 's/^BACKUP_ROOT=//p' "$env_file" | tail -n 1)}
|
||||
case "$backup_root" in
|
||||
/*) ;;
|
||||
*) echo "BACKUP_ROOT must be an absolute path" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
exec 9>"$repo/.maintenance.lock"
|
||||
if ! flock -n 9; then
|
||||
echo "Another RF4 Spotter maintenance run is active" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export COMPOSE_ENV_FILE="$env_file"
|
||||
./deploy/backup.sh "$backup_root"
|
||||
compose="docker compose --env-file $env_file -f compose.production.yaml"
|
||||
$compose exec -T api python -m app.cli cleanup-retention
|
||||
$compose exec -T api python -m app.cli cleanup-retention --apply
|
||||
echo "Daily maintenance completed"
|
||||
Reference in New Issue
Block a user