/opt/SIA/log/siacore.log {
    missingok
    notifempty
    compress
    size 5M
    copytruncate
    dateext
    dateformat -%s
    su root root
    # do not logrotate during service mode
    prerotate
    	/opt/SIA/scripts/check_service_mode.sh
    endscript
    # restart SIA core to switch to the new log file
    postrotate
        # Native systemd service: no action needed (copytruncate + StandardOutput=append)
        if systemctl show -p FragmentPath "siacore" 2>/dev/null | grep -q "/etc/systemd/system/\|/lib/systemd/system/"; then
            true
        # Generated unit from init.d: send SIGHUP to reopen log file
        elif systemctl show -p FragmentPath "siacore" 2>/dev/null | grep -q "/run/systemd/generator"; then
            [ -f "/var/run/siacore.pid" ] && kill -HUP $(cat "/var/run/siacore.pid") 2>/dev/null
        # SysVinit system: restart service
        elif [ -x "/etc/init.d/siacore" ]; then
            /etc/init.d/siacore restart 2>/dev/null
        fi
    endscript
}
