标记部分为启动文件和配置文件路径,以及lock文件路径。其他地方不作修改
在/etc/rc.d/init.d下面添加可执行文件,比如是11
就能使用service 11 start|stop|restart等命令了,注册service服务的好处是还能加入chkconfig中
#!/bin/sh
# Source function library.
. /etc/rc.d/init.d/functions
if [ -x /usr/sbin/zabbix_agentd ]; then
exec=/usr/sbin/zabbix_agentd
else
exit 5
fi
prog=${exec##*/}
conf=/etc/zabbix/zabbix_agentd.conf
pidfile=$(grep -e "^PidFile=.*$" $conf | cut -d= -f2)
timeout=10
lockfile=/var/lock/subsys/zabbix-agent
start()
{
echo -n $"Starting Zabbix agent: "
daemon $exec -c $conf
rv=$?
echo
[ $rv -eq 0 ] && touch $lockfile
return $rv
}
stop()
{
echo -n $"Shutting down Zabbix agent: "
killproc -p $pidfile -d $timeout $prog
rv=$?
echo
[ $rv -eq 0 ] && rm -f $lockfile
return $rv
}
restart()
{
stop
start
}
case "$1" in
start|stop|restart)
$1
;;
force-reload)
restart
;;
status)
status -p $pidfile $prog
;;
try-restart|condrestart)
if status $prog >/dev/null ; then
restart
fi
;;
>
action $"Service ${0##*/} does not support the> exit 3
;;
*)
echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
exit 2
;;
esac |