我正在尝试使用 puppet 管理 cherrypy 服务。但是,当应用配置时,cherryd 最终没有 PID 文件,尽管该进程已启动并正在运行。由于 PID 文件丢失,我无法再停止该进程/etc/init.d/mycherryd stop
(除非我修改手工制作的 init 脚本以查找 PIDps
或类似的东西。)
$ /etc/init.d/mycherryd status
cherryd dead but subsys locked
问题似乎是,puppet 在确保 cherryd 正在运行(如清单中所指定)后立即尝试刷新/重新启动 cherryd(由配置文件中的更改触发),而 cherrypy 在仍在执行其启动过程时无法停止和启动(重新启动)。
这个问题有明确的解决方案吗?这是 cherrypy 方面的错误吗?或者我可以编写一个 puppet 清单,以便仅在服务启动并运行后才调用刷新吗?欢迎提出任何建议。
cherrypy日志
看看 cherrypy 如何在启动过程中捕获 SIGTERM 并开始监听。
:cherrypy.error[18666] 2010-02-12 13:10:23,551 INFO: ENGINE Listening for SIGHUP.
:cherrypy.error[18666] 2010-02-12 13:10:23,552 INFO: ENGINE Listening for SIGTERM.
:cherrypy.error[18666] 2010-02-12 13:10:23,552 INFO: ENGINE Listening for SIGUSR1.
:cherrypy.error[18666] 2010-02-12 13:10:23,552 INFO: ENGINE Bus STARTING
:cherrypy.error[18671] 2010-02-12 13:10:23,554 INFO: ENGINE Daemonized to PID: 18671
:cherrypy.error[18671] 2010-02-12 13:10:23,554 INFO: ENGINE PID 18671 written to '/var/mycherryd/cherry.pid'.
:cherrypy.error[18671] 2010-02-12 13:10:23,555 INFO: ENGINE Started monitor thread '_TimeoutMonitor'.
:cherrypy.error[18670] 2010-02-12 13:10:23,556 INFO: ENGINE Forking twice.
:cherrypy.error[18666] 2010-02-12 13:10:23,557 INFO: ENGINE Forking once.
:cherrypy.error[18671] 2010-02-12 13:10:23,716 INFO: ENGINE Caught signal SIGTERM.
:cherrypy.error[18671] 2010-02-12 13:10:23,716 INFO: ENGINE Bus STOPPING
:cherrypy.error[18671] 2010-02-12 13:10:23,716 INFO: ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('0.0.0.0', 12380)) already shut down
:cherrypy.error[18671] 2010-02-12 13:10:23,717 INFO: ENGINE Stopped thread '_TimeoutMonitor'.
:cherrypy.error[18671] 2010-02-12 13:10:23,717 INFO: ENGINE Bus STOPPED
:cherrypy.error[18671] 2010-02-12 13:10:23,732 INFO: ENGINE Bus EXITING
:cherrypy.error[18671] 2010-02-12 13:10:23,759 INFO: ENGINE PID file removed: '/var/mycherryd/cherry.pid'.
:cherrypy.error[18671] 2010-02-12 13:10:23,782 INFO: ENGINE Bus EXITED
:cherrypy.error[18671] 2010-02-12 13:10:23,792 INFO: ENGINE Serving on 0.0.0.0:12380
:cherrypy.error[18671] 2010-02-12 13:10:23,826 INFO: ENGINE Bus STARTED
木偶日志
puppet 在确保服务正在“运行”后立即尝试刷新服务。
Feb 12 13:10:22 localhost puppetd[8159]: (//mycherrypy/File[conffiles]) Scheduling refresh of Service[cherryd]
Feb 12 13:10:22 localhost last message repeated 12 times
Feb 12 13:10:23 localhost puppetd[8159]: (//mycherrypy/Service[mycherryd]/ensure) ensure changed 'stopped' to 'running'
Feb 12 13:10:23 localhost puppetd[8159]: (//mycherrypy/Service[mycherryd]) Triggering 'refresh' from 13 dependencies
Feb 12 13:11:23 localhost puppetd[8159]: (//mycherrypy/Service[mycherryd]) Failed to call refresh on Service[mycherryd]: Could not stop Service[mycherryd]: Execution of '/sbin/service mycherryd stop' returned 1: at /etc/puppet/manifests/mycherrypy.pp:161
Feb 12 13:11:24 localhost puppetd[8159]: Value of 'preferred_serialization_format' (pson) is invalid for report, using default (marshal)
Feb 12 13:11:24 localhost puppetd[8159]: Finished catalog run in 99.25 seconds
Puppet 清单摘录
class mycherrypy {
file {
'rpm':
path => "/tmp/${apiserver}.i386.rpm",
source => "${fileserver}/${apiserver}.i386.rpm";
'conffiles':
require => Package["${apiserver}"],
path => "${service_home}/config/",
ensure => present,
source => "${fileserver}/config/",
notify => Service["mycherryd"];
}
package {
"$apiserver":
provider => 'rpm',
source => "/tmp/${apiserver}.i386.rpm",
ensure => latest;
}
service {
"mycherryd":
require => [File["conffiles"], Package["${apiserver}"]],
ensure => running,
provider => redhat,
hasstatus => true;
}
}
答案1
尝试将属性添加hasrestart => true
到您的mycherryd
服务资源;这将告诉 puppet 运行“service mycherryd restart”而不是“service mycherryd stop +
service mycherryd start”。
还要确保 init 脚本本身的状态代码是合理的;通常情况下,init 脚本作者不遵循退出代码的 LSB 规范-- 即运行service mycherryd stop; echo $?
,它应该显示 0 表示成功退出。如果没有,puppet 将很难管理服务,mycherryd 维护人员应该修复他们的脚本。