30 lines
1.1 KiB
Bash
30 lines
1.1 KiB
Bash
#!/usr/bin/env bash
|
|
# Wrapper invoked by cron on docker-1/docker-2/docker-3 to rotate the shared
|
|
# Traefik access/error logs (see traefik-logs.conf for the "full why").
|
|
#
|
|
# Because /volume1/docker/traefik/logs is the SAME physical CephFS path on
|
|
# all three nodes, and cron on all three nodes runs this independently, we
|
|
# use a shared flock (also on the CephFS mount, so it's visible cluster-wide)
|
|
# to guarantee only one node actually executes logrotate at a time, and a
|
|
# SHARED state file so whichever node runs it knows the true last-rotated
|
|
# time regardless of which node rotated it last. If a node is down, the
|
|
# other two still cover the schedule -- none of this relies on a specific
|
|
# node being up.
|
|
set -euo pipefail
|
|
|
|
LOCK_DIR="/volume1/docker/traefik/logrotate-state"
|
|
LOCK_FILE="$LOCK_DIR/rotate.lock"
|
|
STATE_FILE="$LOCK_DIR/status"
|
|
CONF_FILE="/etc/logrotate.d/traefik-logs"
|
|
|
|
mkdir -p "$LOCK_DIR"
|
|
touch "$STATE_FILE"
|
|
|
|
exec 200>"$LOCK_FILE"
|
|
if ! flock -n 200; then
|
|
# Another node already holds the lock this cycle -- normal, not an error.
|
|
exit 0
|
|
fi
|
|
|
|
/usr/sbin/logrotate -s "$STATE_FILE" "$CONF_FILE"
|