四、class中资源的说明
1、group和user是定义zabbix用户,看字面含义应该就能理解,就不多说了。
2、file资源
/home/zabbix/zabbix-1.8.9.tar.gz #zabbix安装的源码包,本例中zabbix是从源码编译的
/home/zabbix/zabbix_install.sh #zabbix自动安装的脚本文件,下面会介绍内容
/etc/zabbix/zabbix_agentd.conf #zabbix客户端守护进程的配置文件,这里不是重点,就不介绍了
/etc/init.d/zabbix_agentd #zabbix客户端服务的启动和关闭脚本,下面会介绍
3、exec资源
exec {
"bash zabbix_install.sh": #定义执行脚本
cwd=>"/home/zabbix",
#command => "./zabbix_install.sh",
path=>["/bin","/sbin","/usr/bin","/usr/sbin"],
creates=>"/usr/local/sbin/zabbix_agentd"
}
exec {
"mkdir /home/zabbix": #定义创建zabbix用户的家目录
creates => "/home/zabbix",
path=>["/bin","/sbin","/usr/bin","/usr/sbin"]
}
exec {
"mkdir /etc/zabbix": #定义创建zabbix的配置文件存放目录
creates => "/etc/zabbix",
path=>["/bin","/sbin","/usr/bin","/usr/sbin"]
}
4、zabbix_install.sh脚本内容
service zabbix_agentd stop >>/home/zabbix/test1
cd /home/zabbix/
echo " cd /home/zabbix/" >>/home/zabbix/test1
tar xvfz zabbix-1*.tar.gz >>/home/zabbix/test1
cd zabbix-1*
./configure --enable-agent --enable-java >>/home/zabbix/test1
make install >>/home/zabbix/test1
service zabbix_agentd restart >>/home/zabbix/test1
5、zabbix_agentd脚本内容
#!/bin/bash
#
# chkconfig: - 55 45
# description: zabbix_agentd
# probe: false
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up. If you are running without a network, comment this out.
[ "${NETWORKING}" = "no" ] && exit 0
RETVAL=0
progdir="/usr/local/sbin/"
prog="zabbix_agentd"
start() {
# Start daemons.
if [ -n "`/sbin/pidof $prog`" ]; then
echo -n "$prog: already running"
failure $"$prog start"
echo
return 1
fi
echo -n $"Starting $prog: "
# we can't seem to use daemon here - emulate its functionality
su -c $progdir$prog - $USER
RETVAL=$?
usleep 100000
if [ -z "`/sbin/pidof $progdir$prog`" ]; then
# The child processes have died after fork()ing, e.g.
# because of a broken config file
RETVAL=1
fi
[ $RETVAL -ne 0 ] && failure $"$prog startup"
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog && success $"$prog startup"
echo
return $RETVAL
}
stop() {
RETVAL=0
pid=
# Stop daemons.
echo -n $"Stopping $prog: "
pid=`/sbin/pidof -s $prog`
if [ -n "$pid" ]; then
kill -TERM $pid
else
failure $"$prog stop"
echo
return 1
fi
RETVAL=$?
[ $RETVAL -ne 0 ] && failure $"$prog stop"
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog && success $"$prog stop"
echo
return $RETVAL
}
rh_status() {
status -p /tmp/zabbix_agentd.pid $prog
}
restart() {
stop
# wait for forked daemons to die
usleep 2000000
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
rh_status
;;
condrestart)
[ -f /var/lock/subsys/$prog ] && restart
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart}"
exit 1
esac
exit $?
五、关于puppet的细节说明
1、service部分
服务脚本必须有status模块来表明状态,否则puppet判断不了服务状态,试图启动正在运行的服务
例如zabbix_agentd启动脚本就需要做如下添加
--- /etc/init.d/zabbix_agentd 2011-12-05 16:26:28.048066712 +0800
+++ /tmp/puppet-file20111205-2361-sj1da3-0 2011-12-05 16:28:38.233062213 +0800
@@ -59,6 +59,10 @@
echo
return $RETVAL
}
+
+rh_status() {
+ status -p /tmp/zabbix_agentd.pid $prog
+}
restart() {
stop
# wait for forked daemons to die
@@ -77,6 +81,9 @@
restart)
restart
;;
+ status)
+ rh_status
+ ;;
condrestart)
[ -f /var/lock/subsys/$prog ] && restart
;;
2、关于 zabbix源码包中自带的redhat zabbix_agentd服务脚本
usleep 为1000000 也就是1s,结果时间短点造成判断服务shutdown的时候出错,本来shutdown了,还认为running,其结果是restart不成功
修改成2s才搞定。
######################
#有读者可能会注意到zabbix的class文件内容比较简单,是的,这是11年开始研究puppet搞的早期版本,这里拿来作为例子进行说明。
阅读(5443) | 评论(0) | 转发(0) |