#!/bin/sh # # Daily maintenance for Archie 3.5 — run as the archie user (e.g. via cron or # the archie-arcontrol.timer systemd unit). # prog=$0 MAIL=${MAIL:-mail} PATH=/bin:/usr/bin:/usr/local/bin export PATH usage() { cat - </dev/null 2>&1 ; then debug "systemctl kill --signal=USR2 archie-dirsrv" systemctl kill --signal=USR2 archie-dirsrv.service || true else pid=$(ps aux | grep '[d]irsrv' | awk '{print $2}' | head -1) if [ -n "$pid" ] ; then debug "kill -USR2 $pid" kill -USR2 "$pid" || true fi fi } abort() { echo "Problem with $0. Aborting" exit 2 } # Default stats destination — override with -c dest="" MAILRC=/dev/null export MAILRC v="" while [ $# -gt 0 ] ; do case $1 in -c) if [ $# -gt 1 ] ; then shift dest="${dest:+$dest,}$1" else echo "E-mail address required for -c" usage fi ;; -x) set -x ;; -v) verbose="y" ; v="-v" ;; -h) usage ;; *) echo "Unknown option [$1]" ; usage ;; esac shift done # gzip is always present on modern Linux; keep the check for safety if gzip /dev/null 2>&1 ; then gzip="y" else gzip="n" echo "Note: gzip not found — log archives will not be compressed." fi home=$(get_home archie) pfslog="$home/pfs/pfs.log" pfshistory="$home/pfs/history" # ── rotate archie logs ─────────────────────────────────────────────────────── debug "Cleaning up archie log files in $home/logs" cd "$home/logs" || fatal "can't cd to $home/logs" [ -d history ] || mkdir history || abort for l in *.log ; do [ -f "$l" ] || continue "$home/bin/rotate" $v -d "$home/logs/history" -c "$l" 32 chown archie "$l" done # ── rotate Prospero log ────────────────────────────────────────────────────── debug "Rotating Prospero log" cd "$home/pfs" || fatal "can't cd to $home/pfs" [ -d history ] || mkdir history || abort "$home/bin/rotate" $v "$pfslog" chown archie "$pfslog" restart_dirsrv # ── statistics report ──────────────────────────────────────────────────────── if [ -n "$dest" ] ; then debug "Generating Prospero statistics" cat "$pfshistory"/pfs.log.* 2>/dev/null | \ "$home/bin/prospero-stats.pl" | \ $MAIL -s "Archie Prospero Statistics" "$dest" fi # ── archive and trim old Prospero logs ────────────────────────────────────── debug "Archiving Prospero log" if cat "$pfshistory"/pfs.log.* 2>/dev/null | \ "$home/bin/trimplog.pl" $v -d "$pfshistory" -g "$gzip" ; then debug "Trimming archived Prospero log" rm -f "$pfshistory"/pfs.log.* fi cd "$pfshistory" || fatal "can't cd to $pfshistory" debug "Removing history files older than 180 days" find . -mtime +180 -print | xargs rm -f -- if [ "$gzip" = "n" ] ; then debug "Compressing log files older than 7 days" find . -mtime +7 -name '*.log*' -print | xargs gzip -f -- fi