1238104Sdes#!/bin/sh
2238104Sdes#
3238104Sdes# Copyright (c) 2001-2003
4238104Sdes#	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
5238104Sdes#	All rights reserved.
6238104Sdes#
7238104Sdes# Author: Harti Brandt <harti@freebsd.org>
8238104Sdes# 
9238104Sdes# Redistribution and use in source and binary forms, with or without
10238104Sdes# modification, are permitted provided that the following conditions
11238104Sdes# are met:
12238104Sdes# 1. Redistributions of source code must retain the above copyright
13238104Sdes#    notice, this list of conditions and the following disclaimer.
14238104Sdes# 2. Redistributions in binary form must reproduce the above copyright
15238104Sdes#    notice, this list of conditions and the following disclaimer in the
16238104Sdes#    documentation and/or other materials provided with the distribution.
17238104Sdes# 
18238104Sdes# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19238104Sdes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20238104Sdes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21238104Sdes# ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
22238104Sdes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23238104Sdes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24238104Sdes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25238104Sdes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26238104Sdes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27238104Sdes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28238104Sdes# SUCH DAMAGE.
29238104Sdes#
30238104Sdes# $Begemot: bsnmp/snmpd/snmpd.sh,v 1.3 2004/08/06 08:47:13 brandt Exp $
31238104Sdes#
32238104Sdes# SNMPd startup script
33238104Sdes#
34238104SdesSNMPD=/usr/local/bin/bsnmpd
35238104SdesPID=/var/run/snmpd.pid
36238104SdesCONF=/etc/snmpd.conf
37238104Sdes
38238104Sdescase "$1" in
39238104Sdes
40238104Sdesstart)
41238104Sdes	if [ -r ${PID} ] ; then
42238104Sdes		if kill -0 `cat ${PID}` ; then
43238104Sdes			echo "snmpd already running -- pid `cat ${PID}`" >/dev/stderr
44238104Sdes			exit 1
45238104Sdes		fi
46238104Sdes		rm -f ${PID}
47238104Sdes	fi
48246854Sdes	if ${SNMPD} -c ${CONF} -p ${PID} ; then
49246854Sdes		echo "snmpd started"
50246854Sdes	fi
51246854Sdes	;;
52238104Sdes
53238104Sdesstop)
54246854Sdes	if [ -r ${PID} ] ; then
55246854Sdes		if kill -0 `cat ${PID}` ; then
56246854Sdes			if kill -15 `cat ${PID}` ; then
57246854Sdes				echo "snmpd stopped"
58246854Sdes				exit 0
59238104Sdes			fi
60238104Sdes			echo "cannot kill snmpd" >/dev/stderr
61238104Sdes			exit 1
62238104Sdes		fi
63238104Sdes		echo "stale pid file -- removing" >/dev/stderr
64238104Sdes		rm -f ${PID}
65238104Sdes		exit 1
66238104Sdes	fi
67238104Sdes	echo "snmpd not running" >/dev/stderr
68238104Sdes	;;
69238104Sdes
70238104Sdesstatus)
71238104Sdes	if [ ! -r ${PID} ] ; then
72238104Sdes		echo "snmpd not running"
73238104Sdes	elif kill -0 `cat ${PID}` ; then
74238104Sdes		echo "snmpd pid `cat ${PID}`"
75238104Sdes	else
76238104Sdes		echo "stale pid file -- pid `cat ${PID}`"
77269257Sdes	fi
78269257Sdes	;;
79238104Sdes
80238104Sdes*)
81238104Sdes	echo "usage: `basename $0` {start|stop|status}"
82238104Sdes	exit 1
83238104Sdesesac
84238104Sdes
85238104Sdesexit 0
86246854Sdes