#!/bin/sh # description: start/stop Clam AntiVirus scanner daemon # # default: S/K41 0/K41 1/K41 2/S86 # License: CDDL 1.0 - see http://www.opensource.org/licenses/CDDL-1.0 # Copyright (c) 2006-2014 Jens Elkner. All rights reserved. # $Id$ # default clamd configuration file CONF=/etc/clamav/clamd.conf # default file descriptor limit integer FDLIMIT=1024 NAME="Clam AntiVirus scanner daemon" SPATH=@CLIENT_BASEDIR@/sbin DAEMON="clamd" . /lib/svc/share/smf_include.sh function getSvcProp { typeset -n RES=$2 typeset VAL="${ svcprop -p "$1" ${SMF_FMRI} 2>/dev/null ; }" [[ ${VAL} != '""' && -n ${VAL} ]] && RES="${VAL}" || RES="$3" } [[ -z ${SMF_FMRI} ]] && SMF_FMRI='clamscan:default' case "$1" in start) getSvcProp config/file CONF "${CONF}" if [[ ! -r ${CONF} ]]; then print -u2 "Unable to read config file '${CONF}'." exit ${SMF_EXIT_ERR_CONFIG} fi # in case FixStaleSocket is not enabled, not doing this would # prevent it to work on the next start SOCKET='' while read KEY VAL TAIL ; do [[ ${KEY} == 'LocalSocket' ]] && SOCKET="${VAL}" && break done < "${CONF}" if [[ -n ${SOCKET} && -r ${SOCKET} ]]; then if ! rm -f "${SOCKET}" ; then print -u2 "Unable to remove ${SOCKET} - as long as it exist, ${DAEMON} would not start. So remove it manually, please." exit ${SMF_EXIT_ERR_PERM} fi fi getSvcProp config/fd_limit SOCKET 1024 [[ ${SOCKET} =~ [0-9]+ ]] && FDLIMIT=${SOCKET} (( FDLIMIT >= 64 )) && ulimit -n ${FDLIMIT} print "Starting ${NAME} ..." if ! ${SPATH}/${DAEMON} -c "${CONF}" ; then print -u2 "'${SPATH}/${DAEMON} -c ${CONF}' failed." exit ${SMF_EXIT_ERR_FATAL} fi print 'done.' ;; stop|reload|log) integer CID getSvcProp restarter/contract CID 0 if (( ! CID )); then print -u2 "${SMF_FMRI} is not running." else # NOTE: reload just reloads the DBs, not the config! SIG='USR2' [[ $1 == 'stop' ]] && SIG='TERM' || { [[ $1 == 'log' ]] && SIG='HUP' ; } print "Sending SIG${SIG} to contract ${CID} ..." smf_kill_contract "${CID}" "${SIG}" print 'done.' fi ;; *) print "Usage: $0 { start | stop | reload | log }" exit ${SMF_EXIT_ERR_FATAL} ;; esac exit ${SMF_EXIT_OK}