#========================>linux之snmpd启动脚本注释-一灯
#!/bin/bash
# ucd-snmp init file for snmpd
#
# chkconfig: - 50 50
# description: Simple Network Management Protocol (SNMP) Daemon 简单网络管理协议进程
#
# processname: /usr/sbin/snmpd 程序名
# config: /etc/snmp/snmpd.conf
# config: /usr/share/snmp/snmpd.conf
# pidfile: /var/run/snmpd
# source function library
. /etc/init.d/functions
OPTIONS="-Lsd -Lf /dev/null -p /var/run/snmpd.pid -a"
if [ -e /etc/sysconfig/snmpd.options ]; then #-e文件存在为真
. /etc/sysconfig/snmpd.options
fi
RETVAL=0 #一般都定义一个变量当做命令运行状态码
prog="snmpd"
start() {
echo -n contentquot;Starting $prog: "
if [ $UID -ne 0 ]; then #判断是不是uid为0的用户,不是就设置状态码1,执行failure函数(在/etc/init.d/functions)
RETVAL=1
failure
else #反之则执行snmpd守护进程,并在/var/locak/subsys下生成一个snmpd文件
daemon /usr/sbin/snmpd $OPTIONS
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/snmpd
fi;
echo
return $RETVAL
}
stop() { #停止函数.killproc 进程名字,并删除进程锁文件/var/lock/subsys/ 很多程序锁文件都放在该目录下
echo -n contentquot;Stopping $prog: "
if [ $UID -ne 0 ]; then
RETVAL=1
failure
else
killproc /usr/sbin/snmpd
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/snmpd
fi;
echo
return $RETVAL
}
reload(){
echo -n contentquot;Reloading $prog: " #重新加载snmpd killproc /usr/sbin/snmp -HUP
killproc /usr/sbin/snmpd -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){ #重启snmpd进程,stop然后start
stop
start
}
condrestart(){ #重启snmpd
[ -e /var/lock/subsys/snmpd ] && restart
return 0
}
#case 语句根据传递的第一个参数 判断执行命令
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
condrestart)
condrestart
;;
status)
status snmpd
RETVAL=$?
;;
*)
echo contentquot;Usage: $0 {start|stop|status|restart|condrestart|reload}"
RETVAL=1
esac
exit $RETVAL 本文出自 “一灯” 博客,请务必保留此出处http://yidengdashi.blog.51cto.com/1125400/752428
|