Files
EmailHostingPlatform/fix-clamv.sh
Tommy Parnell 86fdc0b3ba stop for now
2025-08-04 04:16:00 -04:00

103 lines
2.4 KiB
Bash

#!/bin/bash
# filepath: fix-clamav.sh
# Fix ClamAV freshclam lock issue
# Run this script if you encounter ClamAV signature update errors
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
info() {
echo -e "${BLUE}INFO: $1${NC}"
}
success() {
echo -e "${GREEN}SUCCESS: $1${NC}"
}
warning() {
echo -e "${YELLOW}WARNING: $1${NC}"
}
error() {
echo -e "${RED}ERROR: $1${NC}" >&2
}
# Check if running as root
if [[ $EUID -ne 0 ]]; then
error "This script must be run as root"
exit 1
fi
info "Fixing ClamAV freshclam lock issue..."
# Stop ClamAV services
info "Stopping ClamAV services..."
systemctl stop clamav-daemon 2>/dev/null || true
systemctl stop clamav-freshclam 2>/dev/null || true
# Wait for services to stop
sleep 3
# Remove any stale lock files
info "Removing stale lock files..."
rm -f /var/log/clamav/freshclam.log.lock
rm -f /var/run/clamav/freshclam.pid
# Check log file permissions
info "Checking log file permissions..."
touch /var/log/clamav/freshclam.log
chown clamav:clamav /var/log/clamav/freshclam.log
chmod 644 /var/log/clamav/freshclam.log
# Update signatures manually
info "Updating ClamAV signatures..."
if sudo -u clamav freshclam --quiet; then
success "ClamAV signatures updated successfully"
else
warning "Manual signature update failed, but services will handle this automatically"
fi
# Restart services
info "Restarting ClamAV services..."
systemctl start clamav-freshclam
sleep 2
systemctl start clamav-daemon
# Check service status
if systemctl is-active --quiet clamav-freshclam; then
success "clamav-freshclam service is running"
else
warning "clamav-freshclam service failed to start"
fi
if systemctl is-active --quiet clamav-daemon; then
success "clamav-daemon service is running"
else
warning "clamav-daemon service failed to start"
fi
# Restart amavis to ensure it can connect to ClamAV
info "Restarting amavis service..."
systemctl restart amavis
if systemctl is-active --quiet amavis; then
success "amavis service is running"
else
warning "amavis service failed to restart"
fi
success "ClamAV fix completed!"
echo
echo -e "${BLUE}Service Status:${NC}"
systemctl status clamav-freshclam --no-pager -l || true
echo
systemctl status clamav-daemon --no-pager -l || true
echo
systemctl status amavis --no-pager -l || true