# DVSwitch consolidated log rotation
# Installed from the DVSwitch-Server_fix project; replaces the twelve
# per-package configs. Retention for SELF-DATED logs (…-YYYY-MM-DD.log, written
# directly by MMDVM_Bridge, the gateways, ircDDBGateway and USRP2M17) is NOT
# done here — logrotate cannot prune them; that is the job of the daily
# dvswitch-log-cleanup script (find -mtime +7 -name "*.log" -delete),
# scheduled by /etc/cron.daily/dvswitch-log-cleanup.
#
# Inventory of the 12 fixed-name logs shipped by the packages:
#   /var/log/dvswitch/Analog_Bridge.log        analog_bridge
#   /var/log/dvswitch/Analog_Processor.log     analog_processor
#   /var/log/dvswitch/Analog_Reflector.log     analog_reflector
#   /var/log/dvswitch/EchoLink_Bridge.log      echolink_bridge
#   /var/log/dvswitch/IAX_Bridge.log           iax_bridge
#   /var/log/dvswitch/Quantar_Bridge.log       quantar_bridge
#   /var/log/dvswitch/STFU.log                 stfu
#   /var/log/ircddbgateway/ircDDBGateway.log   ircddbgateway
#   /var/log/mmdvm/MMDVM_Bridge.log            mmdvm_bridge
#   /var/log/mmdvm/NXDNGateway.log             nxdngateway
#   /var/log/mmdvm/P25Gateway.log              p25gateway
#   /var/log/mmdvm/YSFGateway.log              ysfgateway
# plus /var/log/netcheck, written by netcheck (unit + script).
#
# Design notes, verified empirically against logrotate 3.22:
#   * Rename-based rotation, NOT copytruncate: with copytruncate, logrotate
#     overwrites .1 on every run (history collapses to a single file) and
#     neither `rotate` shifting nor `maxage` pruning ever happens.
#   * The MMDVM-family fixed-name files are usually EMPTY stubs: those daemons
#     write self-dated files and only the daily cleanup ages those out. For an
#     empty stub `notifempty` is a no-op, which is correct.
#   * Fixed-name writers reopen their logs on SIGHUP, so one shared postrotate
#     keeps them writing to the fresh file. Reload errors for stopped services
#     are ignored. The postrotate list was decided by the reload smoke test
#     (vps/vm/40-reload-smoke.sh): analog_bridge REOPENED on HUP (same PID);
#     mmdvm_bridge survives HUP and switches its fd. ircddbgatewayd,
#     nxdngateway, p25gateway, ysfgateway, stfu and quantar_bridge are KILLED
#     or have no working reload — they are excluded from the postrotate, their
#     ExecReload is dropped by the unit fix, and Quantar_Bridge.log/STFU.log
#     get their own copytruncate stanza below.
#   * Patterns must stay disjoint from every other stanza: logrotate refuses a
#     whole config that declares the same log twice ("duplicate log entry").
#   * webproxy/proxy.log intentionally absent: webproxy is replaced by the
#     dashboard API and is not part of the log inventory.

/var/log/dvswitch/Analog_Bridge.log
/var/log/dvswitch/Analog_Processor.log
/var/log/dvswitch/Analog_Reflector.log
/var/log/dvswitch/EchoLink_Bridge.log
/var/log/dvswitch/IAX_Bridge.log
/var/log/ircddbgateway/ircDDBGateway.log
/var/log/mmdvm/MMDVM_Bridge.log
/var/log/mmdvm/NXDNGateway.log
/var/log/mmdvm/P25Gateway.log
/var/log/mmdvm/YSFGateway.log
/var/log/netcheck
{
    daily
    rotate 7
    maxage 7
    missingok
    notifempty
    compress
    create 0644 root root
    sharedscripts
    postrotate
        /usr/bin/systemctl reload analog_bridge analog_processor \
            analog_reflector echolink_bridge iax_bridge mmdvm_bridge \
            >/dev/null 2>&1 || true
    endscript
}

# Quantar_Bridge and STFU are the exceptions (decided by the reload smoke
# test, not assumed): their ExecReload signals are FATAL or absent. Quantar
# dies on kill -2 AND kill -HUP (trixie) / on HUP (bookworm). STFU's HUP
# kills it on trixie and it holds its log fd at least sometimes, but has NO
# working reload left. Rename rotation would leave such writers on the
# renamed inode, so these two logs use copytruncate: no rename, no reload,
# data preserved. Cost: rotate history collapses to a single .1 per cycle
# window (acceptable for two small logs).
/var/log/dvswitch/Quantar_Bridge.log
/var/log/dvswitch/STFU.log
{
    daily
    rotate 7
    maxage 7
    missingok
    notifempty
    compress
    copytruncate
}
