clamd.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. BACKGROUND_TASKS=()
  3. echo "Running freshclam..."
  4. freshclam
  5. (
  6. while true; do
  7. sleep 12600
  8. freshclam
  9. done
  10. ) &
  11. BACKGROUND_TASKS+=($!)
  12. (
  13. while true; do
  14. sleep 10m
  15. SANE_MIRRORS="$(dig +ignore +short rsync.sanesecurity.net)"
  16. for sane_mirror in ${SANE_MIRRORS}; do
  17. CE=
  18. rsync -avp --chown=clamav:clamav --chmod=Du=rwx,Dgo=rx,Fu=rw,Fog=r --timeout=5 rsync://${sane_mirror}/sanesecurity/ \
  19. --include 'blurl.ndb' \
  20. --include 'junk.ndb' \
  21. --include 'jurlbl.ndb' \
  22. --include 'jurbla.ndb' \
  23. --include 'phishtank.ndb' \
  24. --include 'phish.ndb' \
  25. --include 'spamimg.hdb' \
  26. --include 'scam.ndb' \
  27. --include 'rogue.hdb' \
  28. --include 'sanesecurity.ftm' \
  29. --include 'sigwhitelist.ign2' \
  30. --exclude='*' /var/lib/clamav/
  31. CE=$?
  32. chmod 755 /var/lib/clamav/
  33. if [ ${CE} -eq 0 ]; then
  34. while [ ! -z "$(pidof freshclam)" ]; do
  35. echo "Freshclam is active, waiting..."
  36. sleep 5
  37. done
  38. echo RELOAD | nc clamd-mailcow 3310
  39. break
  40. fi
  41. done
  42. sleep 12h
  43. done
  44. ) &
  45. BACKGROUND_TASKS+=($!)
  46. echo "$(clamd -V) is starting... please wait a moment."
  47. nice -n10 clamd &
  48. BACKGROUND_TASKS+=($!)
  49. while true; do
  50. for bg_task in ${BACKGROUND_TASKS[*]}; do
  51. if ! kill -0 ${bg_task} 1>&2; then
  52. echo "Worker ${bg_task} died, stopping container waiting for respawn..."
  53. kill -TERM 1
  54. fi
  55. sleep 10
  56. done
  57. done