aboutsummaryrefslogblamecommitdiff
path: root/net-mgmt/net-snmp/files/snmpd.sh.in
blob: 7ebddd272f706b1b2cdb6a698a4411f0643d5484 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
         

           


                 



                                                         
                               
 
 
                                 

                                                   
                                           
 
              
 






                                                                 

  
          
                  
 
                               
                        
                         
 
                      
 





                                             









                                                           












                                                                              





                                                           

                                                                     



          
                   
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: snmpd
# REQUIRE: DAEMON
#
# Add the following line to /etc/rc.conf to enable snmpd:
#
# snmpd_enable="YES"
# snmpd_flags="<set as needed>"
#

snmpd_enable=${snmpd_enable-"NO"}
snmpd_pidfile=${snmpd_pidfile-"/var/run/snmpd.pid"}
snmpd_conffile=${snmpd_conffile-""}
snmpd_flush_cache=${snmpd_flush_cache-"NO"}

. /etc/rc.subr

load_rc_config net_snmpd

if [ ! -z "$net_snmpd_enable" ]; then
    echo "Warning: \$net_snmpd_enable is obsoleted."
    echo "         Use \$snmpd_enable instead."
    snmpd_enable="$net_snmpd_enable"
    [ ! -z "$net_snmpd_flags" ] && snmpd_flags="$net_snmpd_flags"
fi

name=snmpd
rcvar=snmpd_enable

command=%%PREFIX%%/sbin/${name}
pidfile=${snmpd_pidfile}
start_precmd=snmpd_precmd

load_rc_config ${name}

snmpd_precmd () {
    if checkyesno snmpd_flush_cache; then
	rm -vf /var/net-snmp/.snmp-exec-cache
    fi
}

case "${snmpd_flags}" in
*-p\ *)
	echo "Warning: \$snmpd_flags includes -p option." \
		"Please use \$snmpd_pidfile instead."
	;;
*)
	snmpd_flags="-p ${snmpd_pidfile} ${snmpd_flags}"
	;;
esac

for conffile in ${snmpd_conffile}; do
	if [ ! -z ${conffile} -a -f ${conffile} ]; then
	       if [ -z ${snmpd_conffile_set} ]; then
		       snmpd_conffile_set="${conffile}"
	       else
		       snmpd_conffile_set="${snmpd_conffile_set},${conffile}"
	       fi
	else
	       echo "snmpd configuration file $conffile not set or not found."
	       exit 1
	fi
done

case "${snmpd_flags}" in
*-c\ *)
	echo "Warning: \$snmpd_flags includes -c option." \
		"Please use \$snmpd_conffile instead."
	;;
*)
	if [ ! -z "${snmpd_conffile_set}" ]; then
		snmpd_flags="-c ${snmpd_conffile_set} ${snmpd_flags}"
	fi
	;;
esac

run_rc_command "$1"