rc.clamav 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!@l_prefix@/bin/openpkg rc
  2. ##
  3. ## rc.clamav -- Run-Commands
  4. ##
  5. %config
  6. clamav_enable="$openpkg_rc_def"
  7. clamav_daemons="clamd clamav-milter"
  8. clamav_clamd_flags=""
  9. clamav_clamav_milter_flags=""
  10. clamav_update="daily"
  11. clamav_log_prolog="true"
  12. clamav_log_epilog="true"
  13. clamav_log_numfiles="10"
  14. clamav_log_minsize="1M"
  15. clamav_log_complevel="9"
  16. %common
  17. clamav_cfgfile="@l_prefix@/etc/clamav/clamd.conf"
  18. clamav_pidfile_clamd="@l_prefix@/var/clamav/clamd.pid"
  19. clamav_pidfile_clamav_milter="@l_prefix@/var/clamav/clamav-milter.pid"
  20. clamav_signal () {
  21. [ -f $clamav_pidfile_clamd ] \
  22. && kill -$1 `cat $clamav_pidfile_clamd`
  23. local rc_clamav_clamd=$?
  24. [ -f $clamav_pidfile_clamav_milter ] \
  25. && kill -$1 `cat $clamav_pidfile_clamav_milter`
  26. local rc_clamav_clamav_milter=$?
  27. [ $rc_clamav_clamd -eq 0 \
  28. -o $rc_clamav_clamav_milter -eq 0 ]
  29. }
  30. %status -u @l_rusr@ -o
  31. clamav_usable="unknown"
  32. clamav_active="no"
  33. rcService clamav enable yes && \
  34. clamav_signal 0 && clamav_active="yes"
  35. echo "clamav_enable=\"$clamav_enable\""
  36. echo "clamav_usable=\"$clamav_usable\""
  37. echo "clamav_active=\"$clamav_active\""
  38. %start -u @l_rusr@
  39. rcService clamav enable yes || exit 0
  40. rcService clamav active yes && exit 0
  41. for daemon in $clamav_daemons; do
  42. if [ ".$daemon" = ".clamd" ]; then
  43. @l_prefix@/sbin/clamd \
  44. --config-file=$clamav_cfgfile \
  45. $clamav_clamd_flags
  46. elif [ ".$daemon" = ".clamav-milter" -a -x @l_prefix@/sbin/clamav-milter ]; then
  47. ( umask 002
  48. @l_prefix@/sbin/clamav-milter \
  49. --config-file=$clamav_cfgfile \
  50. --max-children=4 --outgoing --local \
  51. --pidfile=$clamav_pidfile_clamav_milter \
  52. --sendmail-cf=/dev/null \
  53. $clamav_clamav_milter_flags \
  54. local:@l_prefix@/var/clamav/clamav-milter.socket
  55. ) || exit $?
  56. fi
  57. done
  58. %stop -u @l_rusr@
  59. rcService clamav enable yes || exit 0
  60. rcService clamav active no && exit 0
  61. clamav_signal TERM
  62. rm -f $clamav_pidfile_clamd 2>/dev/null || true
  63. rm -f $clamav_pidfile_clamav_milter 2>/dev/null || true
  64. %restart -u @l_rusr@
  65. rcService clamav enable yes || exit 0
  66. rcService clamav active no && exit 0
  67. rc clamav stop
  68. sleep 2
  69. rc clamav start
  70. %quarterly -u @l_rusr@
  71. rcService clamav enable yes || exit 0
  72. if [ ".$clamav_update" = .quarterly ]; then
  73. @l_prefix@/bin/freshclam
  74. if [ $? -ge 10 ]; then exit $?; fi
  75. fi
  76. %hourly -u @l_rusr@
  77. rcService clamav enable yes || exit 0
  78. if [ ".$clamav_update" = .hourly ]; then
  79. @l_prefix@/bin/freshclam
  80. if [ $? -ge 10 ]; then exit $?; fi
  81. fi
  82. %daily -u @l_rusr@
  83. rcService clamav enable yes || exit 0
  84. if [ ".$clamav_update" = .daily ]; then
  85. @l_prefix@/bin/freshclam
  86. if [ $? -ge 10 ]; then exit $?; fi
  87. fi
  88. logfiles=""
  89. for daemon in freshclam $clamav_daemons; do
  90. logfiles="$logfiles @l_prefix@/var/clamav/$daemon.log"
  91. done
  92. shtool rotate -f \
  93. -n $clamav_log_numfiles -s $clamav_log_minsize -d \
  94. -z $clamav_log_complevel -o @l_rusr@ -g @l_rgrp@ -m 644 \
  95. -P "$clamav_log_prolog" \
  96. -E "$clamav_log_epilog; rc clamav restart" \
  97. $logfiles
  98. %weekly -u @l_rusr@
  99. rcService clamav enable yes || exit 0
  100. if [ ".$clamav_update" = .weekly ]; then
  101. @l_prefix@/bin/freshclam
  102. if [ $? -ge 10 ]; then exit $?; fi
  103. fi