mirror of
https://github.com/m1ngsama/TNT.git
synced 2026-02-08 00:54:03 +00:00
Improvements for low-barrier anonymous access: - Enhanced welcome message to clarify anonymous access - Added EASY_SETUP.md guide in Chinese and English - Updated README with anonymous access notes Long-term stability enhancements: - Improved systemd service with auto-restart and resource limits - Added log rotation script (scripts/logrotate.sh) - Added health check script (scripts/healthcheck.sh) - Added cron setup script for automated maintenance - Added anonymous access test suite Testing: - All security features verified (10/10 passed) - Anonymous access tests passed (2/2) - Health check verified This ensures: - Zero-barrier SSH access (any username, any password) - Stable long-term operation with auto-restart - Automated log management - Continuous health monitoring
44 lines
1.1 KiB
Bash
Executable file
44 lines
1.1 KiB
Bash
Executable file
#!/bin/bash
|
|
# TNT Log Rotation Script
|
|
# Keeps chat history manageable and prevents disk space issues
|
|
|
|
LOG_FILE="${1:-/var/lib/tnt/messages.log}"
|
|
MAX_SIZE_MB="${2:-100}"
|
|
KEEP_LINES="${3:-10000}"
|
|
|
|
# Check if log file exists
|
|
if [ ! -f "$LOG_FILE" ]; then
|
|
echo "Log file $LOG_FILE does not exist"
|
|
exit 0
|
|
fi
|
|
|
|
# Get file size in MB
|
|
FILE_SIZE=$(du -m "$LOG_FILE" | cut -f1)
|
|
|
|
# Rotate if file is too large
|
|
if [ "$FILE_SIZE" -gt "$MAX_SIZE_MB" ]; then
|
|
echo "Log file size: ${FILE_SIZE}MB, rotating..."
|
|
|
|
# Create backup
|
|
BACKUP="${LOG_FILE}.$(date +%Y%m%d_%H%M%S)"
|
|
cp "$LOG_FILE" "$BACKUP"
|
|
|
|
# Keep only last N lines
|
|
tail -n "$KEEP_LINES" "$LOG_FILE" > "${LOG_FILE}.tmp"
|
|
mv "${LOG_FILE}.tmp" "$LOG_FILE"
|
|
|
|
# Compress old backup
|
|
gzip "$BACKUP"
|
|
|
|
echo "Log rotated. Backup: ${BACKUP}.gz"
|
|
echo "Kept last $KEEP_LINES lines"
|
|
else
|
|
echo "Log file size: ${FILE_SIZE}MB (under ${MAX_SIZE_MB}MB limit)"
|
|
fi
|
|
|
|
# Clean up old compressed logs (keep last 5)
|
|
LOG_DIR=$(dirname "$LOG_FILE")
|
|
cd "$LOG_DIR" || exit
|
|
ls -t messages.log.*.gz 2>/dev/null | tail -n +6 | xargs rm -f 2>/dev/null
|
|
|
|
echo "Log rotation complete"
|