|
故障现象
安装有mcollective客户端的机器运行mco命令
[iyunv@linuxmaster1poc manifests]# mco puppet -v runonce
Discovering hosts using the mc method for 2 second(s) .... 2
* [ ============================================================> ] 2 / 2
linux58poc : OK
{:summary=> "Started a background Puppet run using the 'puppet agent --onetime --daemonize --color=false --splay --splaylimit 30' command"}
linux57poc : OK
{:summary=> "Started a background Puppet run using the 'puppet agent --onetime --daemonize --color=false --splay --splaylimit 30' command"}
---- rpc stats ----
Nodes: 2 / 2
Pass / Fail: 2 / 0
Start Time: Wed Nov 27 20:32:17 +0800 2013
Discovery Time: 2003.46ms
Agent Time: 2144.60ms
Total Time: 4148.06ms
节点出现了Caught TERM; calling stop
[iyunv@linux57poc ~]# tailf /var/log/messages
Nov 27 20:50:04 linux57poc kernel: hdc: drive_cmd: status=0x51 { DriveReady SeekComplete Error }
Nov 27 20:50:04 linux57poc kernel: hdc: drive_cmd: error=0x04 { AbortedCommand }
Nov 27 20:50:04 linux57poc kernel: ide: failed opcode was: 0xec
Nov 27 20:50:04 linux57poc smartd[3086]: Device: /dev/hdc, not ATA, no IDENTIFY DEVICE Structure ****
Nov 27 20:50:04 linux57poc smartd[3086]: Device: /dev/sda, opened
Nov 27 20:50:04 linux57poc smartd[3086]: Device: /dev/sda, IE (SMART) not enabled, skip device Try 'smartctl -s on /dev/sda' to turn on SMART features
Nov 27 20:50:04 linux57poc smartd[3086]: Monitoring 0 ATA and 0 SCSI devices
Nov 27 20:50:04 linux57poc smartd[3088]: smartd has fork()ed into background mode. New PID=3088.
Nov 27 20:50:05 linux57poc avahi-daemon[3052]: Server startup complete. Host name is linux57poc.local. Local service cookie is 3157425857.
Nov 27 20:32:19 linux57poc puppet-agent[3302]: Reopening log files
Nov 27 20:32:28 linux57poc puppet-agent[3302]: Caught TERM; calling stop
问题原因
出现这个问题一般都是使用 mcollective 来管理 puppet 。 因为使用了 mcollective,因此 puppet agent 不需要再运行,因此一般都会将 puppet agent 服务停掉。因此包含下面的 manifest :
[iyunv@linuxmaster1poc manifests]# cat service.pp
class puppet::service{
service { 'puppet':
ensure => stopped,
hasstatus => true,
hasrestart => true,
enable => false,
}
}
当在节点中包含以上的 manifest 时,mco puppet 触发 puppet agent 执行后, puppet agent 发现 Service['puppet'], 且要求的状态为 stopped, 因此就会将 puppet agent 停掉。因此就出现了:
Nov 27 20:32:28 linux57poc puppet-agent[3302]: Caught TERM; calling stop
问题分析
但是为什么直接运行和 mco puppet 会出现不一样的结果?
[iyunv@linux57poc ~]# puppet agent -t
info: Retrieving plugin
info: Loading facts in /var/lib/puppet/lib/facter/fact_apply.rb
info: Caching catalog for puppet_linux57poc.gov.shanghaigm.com
info: Applying configuration version '1385555547'
notice: /Stage[main]/Mcollective::Facter/File[/etc/mcollective/facts.yaml]/content:
--- /etc/mcollective/facts.yaml 2013-11-25 15:34:08.000000000 +0800
+++ /tmp/puppet-file20131127-3628-1jp2s6u-0 2013-11-27 20:57:02.000000000 +0800
@@ -1,89 +1,89 @@
---
...
\ No newline at end of file
info: FileBucket adding {md5}cb3e6e93f7fd804f7e87f3340f624745
info: /Stage[main]/Mcollective::Facter/File[/etc/mcollective/facts.yaml]: Filebucketed /etc/mcollective/facts.yaml to puppet with sum cb3e6e93f7fd804f7e87f3340f624745
notice: Finished catalog run in 0.51 seconds
比较两个命令运行的区别:
mco puppet -v runonce实际运行的是以下命令
puppet agent --onetime --daemonize --color=false --splay --splaylimit 30
puppet agent -t实际运行的是以下命令
puppet agent --onetime --verbose --ignorecache --no-daemonize --no-usecacheonfailure --detailed-exit-codes --no-splay
因此上面两个命令关键的差别就在于一个是 –daemonize (后台运行),另一个是 –no-daemonize (前台交互运行),这两者又有什么区别呢?
一般后台运行程序会生成一个 pid 文件,通过服务控制脚本查看状态时(service puppet status)会检查这个 pid 文件,如果文件存在,则认为服务在运行,并输出 pid 文件中的 pid 值;当文件不存在时,则认为服务未运行。 ?在使用 –daemonize 参数运行 puppet agent时, puppet 会产生一个 pid 文件,因此使用 service puppet status 去查询状态时会读取到这个文件,认为 puppet agent 正在运行, 而 manifest 指示 Service['puppet'] 应该处于停止状态,因此会停掉 puppet 服务,因为会杀死 puppet agent 进程。 ?在使用–no-daemonize 参数运行 puppet agent 时,puppet 不会产生 pid 文件,因此 service puppet status 读取到的状态是未运行,因此与 manifest 中要求的一致,因此 puppet agent不会受影响。
问题解决
直接的解决方法就是直接去掉服务运行控制,这样就不会杀掉 puppet agent 进程了。将:
[iyunv@linuxmaster1poc manifests]# cat service.pp
class puppet::service{
service { 'puppet':
ensure => stopped,
hasstatus => true,
hasrestart => true,
enable => false,
}
}
改成:
[iyunv@linuxmaster1poc manifests]# cat service.pp
class puppet::service{
service { 'puppet':
hasstatus => true,
hasrestart => true,
enable => false,
}
}
|
|
|