37b276729843857a76245a4f72482ddf790ba05e
[feed/packages.git] / net / clamav / files / freshclam.init
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 }
20
21 start_service() {
22 local freshclam_config_file UpdateLogFile DatabaseOwner NotifyClamd DatabaseMirror
23
24 validate_freshclam_section freshclam || {
25 echo "validation failed"
26 return 1
27 }
28
29 [ -f /tmp/freshclam.pid ] && echo "already running" && return 0
30
31 mkdir -p /usr/share/clamav
32 mkdir -p /etc/clamav
33 touch /tmp/freshclam.log
34 touch /tmp/freshclam.pid
35
36 mkdir -p $(dirname $FRESHCLAM_CONFIGFILE)
37 ln -sf $freshclam_config_file $FRESHCLAM_CONFIGFILE
38
39 echo "UpdateLogFile " $UpdateLogFile > $FRESHCLAM_CONFIGFILE
40 echo "DatabaseMirror " $DatabaseMirror >> $FRESHCLAM_CONFIGFILE
41 echo "NotifyClamd " $NotifyClamd >> $FRESHCLAM_CONFIGFILE
42 echo "DatabaseOwner " $DatabaseOwner >> $FRESHCLAM_CONFIGFILE
43 echo "CompressLocalDatabase " $CompressLocalDatabase >> $FRESHCLAM_CONFIGFILE
44
45 procd_open_instance
46 procd_set_param command $PROG -d --config-file=$FRESHCLAM_CONFIGFILE -p /tmp/freshclam.pid --no-warnings
47 procd_set_param file $FRESHCLAM_CONFIGFILE
48 procd_close_instance
49 }
50
51 stop_service()
52 {
53 [ ! -f /tmp/freshclam.pid ] && echo "not running" && return 0
54 PID=`cat /tmp/freshclam.pid`
55 kill $PID
56 rm -f /tmp/freshclam.pid
57 }
58
59 service_triggers()
60 {
61 procd_add_reload_trigger "freshclam"
62 procd_add_validation validate_freshclam_section
63 }