freshclam.init (1789B)
1 #!/bin/sh /etc/rc.common 2 # Copyright (C) 2015 OpenWrt.org 3 4 START=90 5 STOP=10 6 7 USE_PROCD=1 8 PROG=/usr/sbin/freshclam 9 FRESHCLAM_CONFIGFILE="/tmp/clamav/freshclam.conf" 10 11 validate_freshclam_section() { 12 uci_validate_section freshclam freshclam "${1}" \ 13 'freshclam_config_file:string' \ 14 'UpdateLogFile:string' \ 15 'DatabaseMirror:string' \ 16 'NotifyClamd:string' \ 17 'DatabaseOwner:string' \ 18 'CompressLocalDatabase:string' \ 19 'DatabaseDirectory:string:' 20 } 21 22 start_service() { 23 local freshclam_config_file UpdateLogFile DatabaseOwner NotifyClamd DatabaseMirror \ 24 DatabaseDirectory 25 26 validate_freshclam_section freshclam || { 27 echo "validation failed" 28 return 1 29 } 30 31 [ -f /tmp/freshclam.pid ] && echo "already running" && return 0 32 33 mkdir -p $DatabaseDirectory 34 mkdir -p /etc/clamav 35 touch /tmp/freshclam.log 36 touch /tmp/freshclam.pid 37 38 mkdir -p $(dirname $FRESHCLAM_CONFIGFILE) 39 ln -sf $freshclam_config_file $FRESHCLAM_CONFIGFILE 40 41 echo "UpdateLogFile " $UpdateLogFile > $FRESHCLAM_CONFIGFILE 42 echo "DatabaseMirror " $DatabaseMirror >> $FRESHCLAM_CONFIGFILE 43 echo "NotifyClamd " $NotifyClamd >> $FRESHCLAM_CONFIGFILE 44 echo "DatabaseOwner " $DatabaseOwner >> $FRESHCLAM_CONFIGFILE 45 echo "CompressLocalDatabase " $CompressLocalDatabase >> $FRESHCLAM_CONFIGFILE 46 echo "DatabaseDirectory " $DatabaseDirectory >> $FRESHCLAM_CONFIGFILE 47 48 procd_open_instance 49 procd_set_param command $PROG -d --config-file=$FRESHCLAM_CONFIGFILE -p /tmp/freshclam.pid --no-warnings 50 procd_set_param file $FRESHCLAM_CONFIGFILE 51 procd_close_instance 52 } 53 54 stop_service() 55 { 56 [ ! -f /tmp/freshclam.pid ] && echo "not running" && return 0 57 PID=`cat /tmp/freshclam.pid` 58 kill $PID 59 rm -f /tmp/freshclam.pid 60 } 61 62 service_triggers() 63 { 64 procd_add_reload_trigger "freshclam" 65 procd_add_validation validate_freshclam_section 66 }