#!/bin/sh # description: start/stop Clam AntiVirus database update daemon # # default: S/K40 0/K40 1/K40 2/S87 # CDDL (http://hub.opensolaris.org/bin/view/Main/licensing) terms apply. # Copyright (c) 2006-2011 Jens Elkner. All rights reserved. # $Id: clamfresh.method 445 2011-08-25 23:08:01Z elkner $ # account, under which clamfresh should run # Default: clamav ACCOUNT=clamav # clamav configuration file - important to be able to inform clamd/milter # about changes in the virus signature database CONF=/etc/clamav/freshclam.conf # # no further changes should be required # if [ `uname -s` = "SunOS" -a -x /usr/bin/svcprop ]; then . /lib/svc/share/smf_include.sh if [ -n "$SMF_FMRI" ]; then val=`svcprop -p start/user $SMF_FMRI` [ -n "$val" ] && [ "$val" != "\"\"" ] && ACCOUNT="$val" val=`svcprop -p config-file/entities $SMF_FMRI | cut -f4- -d/` [ -n "$val" ] && [ "$val" != "\"\"" ] && CONF="/$val" fi ID=/usr/xpg4/bin/id ZN=`/sbin/zonename` if [ "$ZN" = "global" ]; then ZPPID=1 else ZPPID=`pgrep -x zsched 2>/dev/null` fi else SMF_EXIT_OK=0 SMF_EXIT_ERR_FATAL=95 SMF_EXIT_ERR_CONFIG=96 SMF_EXIT_ERR_PERM=100 ZPPID=1 ID=/usr/bin/id fi NAME="Clam AntiVirus signature database update daemon" SPATH=@CLIENT_BASEDIR@/bin DAEMON="freshclam" case "$1" in 'start') if [ ! -f ${CONF} ]; then echo "Missing config file $CONF" exit $SMF_EXIT_ERR_CONFIG fi if [ ! -x $SPATH/$DAEMON ]; then echo "failed (unable to execute $SPATH/$DAEMON)." exit $SMF_EXIT_ERR_FATAL fi PIDS=`pgrep -x -u $ACCOUNT -P $ZPPID $DAEMON` if [ -n "$PIDS" ]; then echo "is already running." exit $SMF_EXIT_OK; fi echo "Starting $NAME ..." if [ `$ID -un` != "$ACCOUNT" ]; then /usr/bin/su - $ACCOUNT -c "$SPATH/$DAEMON -d --config-file=$CONF" else $SPATH/$DAEMON -d --config-file=$CONF fi if [ $? -ne 0 ]; then echo "Error starting $SPATH/$DAEMON -d --config-file=$CONF" exit $SMF_EXIT_ERR_FATAL fi echo "done." ;; 'stop') echo "Stopping $NAME ..." pkill -TERM -x -u $ACCOUNT -P $ZPPID $DAEMON echo "done." ;; *) echo "Usage: $0 { start | stop }" exit $SMF_EXIT_ERR_NOSMF ;; esac exit $SMF_EXIT_OK