clamd.initd-r6 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2013 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. daemon_clamd="/usr/sbin/clamd"
  5. daemon_freshclam="/usr/bin/freshclam"
  6. daemon_milter="/usr/sbin/clamav-milter"
  7. extra_commands="logfix"
  8. depend() {
  9. use net
  10. provide antivirus
  11. }
  12. get_config() {
  13. clamconf | sed 's/["=]//g' | \
  14. awk "{
  15. if(\$0==\"Config file: $1.conf\") S=1
  16. if(S==1&&\$0==\"\") {
  17. print \"$3\"
  18. exit
  19. }
  20. if(S==1&&\$1~\"^$2\$\") {
  21. print \$2!=\"disabled\"?\$2:\"$3\"
  22. exit
  23. }
  24. }"
  25. }
  26. start() {
  27. # populate variables and fix log file permissions
  28. logfix
  29. if [ "${START_CLAMD}" = "yes" ]; then
  30. checkpath --quiet --mode 755 \
  31. --owner "${clamd_user}":"${clamd_user}" \
  32. --directory `dirname ${clamd_socket}`
  33. if [ -S "${clamd_socket}" ]; then
  34. rm -f ${clamd_socket}
  35. fi
  36. ebegin "Starting clamd"
  37. start-stop-daemon --start --quiet \
  38. --nicelevel ${CLAMD_NICELEVEL:-0} \
  39. --ionice ${IONICE_LEVEL:-0} \
  40. --exec ${daemon_clamd}
  41. eend $? "Failed to start clamd"
  42. fi
  43. if [ "${START_FRESHCLAM}" = "yes" ]; then
  44. checkpath --quiet --mode 755 \
  45. --owner "${clamd_user}":"${clamd_user}" \
  46. --directory `dirname ${clamd_socket}`
  47. ebegin "Starting freshclam"
  48. start-stop-daemon --start --quiet \
  49. --nicelevel ${FRESHCLAM_NICELEVEL:-0} \
  50. --ionice ${IONICE_LEVEL:-0} \
  51. --exec ${daemon_freshclam} -- -d
  52. retcode=$?
  53. if [ ${retcode} = 1 ]; then
  54. eend 0
  55. einfo "Virus databases are already up to date."
  56. else
  57. eend ${retcode} "Failed to start freshclam"
  58. fi
  59. fi
  60. if [ "${START_MILTER}" = "yes" ]; then
  61. if [ -z "${MILTER_CONF_FILE}" ]; then
  62. MILTER_CONF_FILE="/etc/clamav-milter.conf"
  63. fi
  64. ebegin "Starting clamav-milter"
  65. start-stop-daemon --start --quiet \
  66. --nicelevel ${MILTER_NICELEVEL:-0} \
  67. --ionice ${IONICE_LEVEL:-0} \
  68. --exec ${daemon_milter} -- -c ${MILTER_CONF_FILE}
  69. eend $? "Failed to start clamav-milter"
  70. fi
  71. }
  72. stop() {
  73. if [ "${START_CLAMD}" = "yes" ]; then
  74. ebegin "Stopping clamd"
  75. start-stop-daemon --stop --quiet --name clamd
  76. eend $? "Failed to stop clamd"
  77. fi
  78. if [ "${START_FRESHCLAM}" = "yes" ]; then
  79. ebegin "Stopping freshclam"
  80. start-stop-daemon --stop --quiet --name freshclam
  81. eend $? "Failed to stop freshclam"
  82. fi
  83. if [ "${START_MILTER}" = "yes" ]; then
  84. ebegin "Stopping clamav-milter"
  85. start-stop-daemon --stop --quiet --name clamav-milter
  86. eend $? "Failed to stop clamav-milter"
  87. fi
  88. }
  89. logfix() {
  90. clamd_socket=$(get_config clamd LocalSocket /run/clamav/clamd.sock)
  91. clamd_user=$(get_config clamd User clamav)
  92. freshclam_user=$(get_config freshclam DatabaseOwner clamav)
  93. if [ "${START_CLAMD}" = "yes" ]; then
  94. # fix clamd log permissions
  95. # (might be clobbered by logrotate or something)
  96. local logfile=$(get_config clamd LogFile)
  97. if [ -n "${logfile}" ]; then
  98. checkpath --quiet \
  99. --owner "${clamd_user}":"${clamd_user}" \
  100. --mode 640 \
  101. --file ${logfile}
  102. fi
  103. fi
  104. if [ "${START_FRESHCLAM}" = "yes" ]; then
  105. # fix freshclam log permissions
  106. # (might be clobbered by logrotate or something)
  107. local logfile=$(get_config freshclam UpdateLogFile)
  108. if [ -n "${logfile}" ]; then
  109. checkpath --quiet \
  110. --owner "${freshclam_user}":"${freshclam_user}" \
  111. --mode 640 \
  112. --file ${logfile}
  113. fi
  114. fi
  115. }