45 lines
1.7 KiB
Bash
45 lines
1.7 KiB
Bash
#!/usr/bin/env bash
|
|
# One-time installer for Traefik log rotation.
|
|
#
|
|
# MUST be run manually, once, on EACH of docker-1, docker-2, docker-3.
|
|
# This is intentionally NOT part of stack-deploy.sh / the Woodpecker
|
|
# pipeline: it installs a host-level cron.d entry and /etc/logrotate.d
|
|
# config, and `docker stack deploy` has no mechanism to reach outside the
|
|
# Swarm/container boundary onto host cron. See README.md for why this needs
|
|
# to run on all three nodes.
|
|
#
|
|
# Usage (from a checkout of this repo, on each node):
|
|
# sudo bash traefik/logrotate/install.sh
|
|
set -euo pipefail
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "Run as root (sudo)." >&2
|
|
exit 1
|
|
fi
|
|
|
|
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
echo "Installing logrotate config..."
|
|
install -m 0644 "$REPO_DIR/traefik-logs.conf" /etc/logrotate.d/traefik-logs
|
|
|
|
echo "Installing rotation wrapper..."
|
|
install -m 0755 "$REPO_DIR/traefik-logrotate.sh" /usr/local/sbin/traefik-logrotate.sh
|
|
|
|
echo "Installing cron.d schedule (every 15 minutes)..."
|
|
cat > /etc/cron.d/traefik-logrotate << 'EOF'
|
|
# Managed by homelab/compose-files traefik/logrotate/install.sh -- do not
|
|
# hand-edit; update traefik/logrotate/*.{conf,sh} in Gitea and re-run
|
|
# install.sh instead.
|
|
*/15 * * * * root /usr/local/sbin/traefik-logrotate.sh
|
|
EOF
|
|
chmod 0644 /etc/cron.d/traefik-logrotate
|
|
|
|
echo "Verifying logrotate config syntax..."
|
|
logrotate -d /etc/logrotate.d/traefik-logs
|
|
|
|
echo "Done. First rotation check runs on the next cron tick (up to 15 min)."
|
|
echo "This only rotates going forward once the file crosses the size threshold."
|
|
echo "To shrink the EXISTING already-large log file, see README.md -- that is"
|
|
echo "a separate, deliberate manual step (not done by this script) because it"
|
|
echo "needs disk headroom awareness first."
|