summaryrefslogtreecommitdiff
path: root/extra/clamav/rc.d
blob: 8e9c6afa936ce5b0991752c9762286f6e8c6de29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

# source application-specific settings
[ -f /etc/conf.d/clamav ] && . /etc/conf.d/clamav

PID_FC=`pidof -o %PPID /usr/bin/freshclam`
PID_CD=`pidof -o %PPID /usr/sbin/clamd`

case "$1" in
  start)
    # if clamd isn't started first, notifyclamd fails at times
    if [ "$START_CLAMD" == "yes" ]; then
       stat_busy "Starting ClamD"
       [ -z "$PID_CD" ] && /usr/sbin/clamd
       if [ $? -gt 0 ]; then
          stat_fail
       else
          add_daemon clamav
          stat_done
       fi
    fi

    # give clamd enough time to start
    sleep 1

    if [ "$START_FRESHCLAM" == "yes" ]; then 
       stat_busy "Starting FreshClam"
       [ -z "$PID_FC" ] && /usr/bin/freshclam -p /var/run/clamav/freshclam.pid -d $FRESHCLAM_OPTS
       if [ $? -gt 0 ]; then
          stat_fail
       else
          add_daemon clamav
          stat_done
       fi
    fi
    ;;
  stop)
    if [ "$START_CLAMD" == "yes" ]; then
       stat_busy "Stopping ClamD"
   	[ -n "$PID_CD" ] && kill $PID_CD &> /dev/null
        if [ $? -gt 0 ]; then
           stat_fail
        else
           rm_daemon clamav
           stat_done
        fi
    fi

    if [ "$START_FRESHCLAM" == "yes" ]; then 
       stat_busy "Stopping FreshClam"
       [ -n "$PID_FC" ] && kill $PID_FC &> /dev/null
       if [ $? -gt 0 ]; then
          stat_fail
       else
          rm_daemon clamav
          stat_done
       fi
    fi
    ;;
  restart)
    $0 stop
    # will not start if not fully stopped, so sleep
    sleep 2
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"  
esac
exit 0