xref: /freebsd/contrib/bsnmp/snmpd/snmpd.sh (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1#!/bin/sh
2#
3# Copyright (c) 2001-2003
4#	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
5#	All rights reserved.
6#
7# Author: Harti Brandt <harti@freebsd.org>
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
22# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28# SUCH DAMAGE.
29#
30# $Begemot: bsnmp/snmpd/snmpd.sh,v 1.3 2004/08/06 08:47:13 brandt Exp $
31#
32# SNMPd startup script
33#
34SNMPD=/usr/local/bin/bsnmpd
35PID=/var/run/snmpd.pid
36CONF=/etc/snmpd.conf
37
38case "$1" in
39
40start)
41	if [ -r ${PID} ] ; then
42		if kill -0 `cat ${PID}` ; then
43			echo "snmpd already running -- pid `cat ${PID}`" >/dev/stderr
44			exit 1
45		fi
46		rm -f ${PID}
47	fi
48	if ${SNMPD} -c ${CONF} -p ${PID} ; then
49		echo "snmpd started"
50	fi
51	;;
52
53stop)
54	if [ -r ${PID} ] ; then
55		if kill -0 `cat ${PID}` ; then
56			if kill -15 `cat ${PID}` ; then
57				echo "snmpd stopped"
58				exit 0
59			fi
60			echo "cannot kill snmpd" >/dev/stderr
61			exit 1
62		fi
63		echo "stale pid file -- removing" >/dev/stderr
64		rm -f ${PID}
65		exit 1
66	fi
67	echo "snmpd not running" >/dev/stderr
68	;;
69
70status)
71	if [ ! -r ${PID} ] ; then
72		echo "snmpd not running"
73	elif kill -0 `cat ${PID}` ; then
74		echo "snmpd pid `cat ${PID}`"
75	else
76		echo "stale pid file -- pid `cat ${PID}`"
77	fi
78	;;
79
80*)
81	echo "usage: `basename $0` {start|stop|status}"
82	exit 1
83esac
84
85exit 0
86