最新消息:

supervisord 未生成 core 文件

core admin 5755浏览 0评论

同事反映一个非常奇怪的现象, supervisor接管应用程序后, 应用程序不能产生core文件。

  1.  登上服务器上查看,果然存在这样的现象,test进程崩溃后,仅仅在系统日志中存在报错日志,(指令地址信息 ,文件的装载地址信息), 但是没有core文件。sysctl -a | g core_pattern 也设置相应 目录

  2.  然后手工执行该程序, 可以产生core文件。

现象明显

  1. 开始检查和对比  接管后的进程中环境变量  和  手工执行程序的环境变量  【具体手法可以借助gdb , 和 查看进程相关的内存文件】

  2. 具体确实差异, supervisor接管后 core file size 依然是0【不能产生core文件】,  手工执行的时候,进程中的core file size 为ulimited【可以产生core文件】

  3. 快下班了,要赶紧解决掉这个,原因可以后面再细查, 确定解决问题办法,只需要将当前进程的这个值更改掉即可, 下面是3种办法 :
    1.借助gdb 直接修改ulimit的一些参数【不推荐】【内核>2.6】
    2.直接修改/proc/xx/limits的参数,echo -n ‘Max open files=unlimited:unlimited’ >/proc/15533/limits  【内核>2.6】
    3.借助prlimit工具 【内核>2.6.36】,prlimit  –pid 25622 –nofile=10240:10240

  4. 为了排除环境的变量的原因, 用python写一个类似supervider类似的程序,父进程产生一个进程来执行目标程序,并且放入到crontab中运行, 代码如下:

    #!/usr/bin/env python
    #coding=utf8
     
    from time import sleep
    import os,signal
    

def chldhandler(signum,stackframe):         while 1:                 try:                         result = os.waitpid(-1,os.WNOHANG)                 except:                         break                 print "Reaped child process %d" % result[0]         signal.signal(signal.SIGCHLD,chldhandler)   signal.signal(signal.SIGCHLD,chldhandler)   try:     pid = os.fork()     if pid == 0:         #os.system("/tmp/a.out")         os.execv("/tmp/a.out",[]) except OSError, e:     pass   sleep(30)

  1. core文件能够正常产生,排除了一些环境变量的因数,就是supervidoer程序本身了,

  2. 顺着/usr/bin/supervisord去查看源代码,  不看不知道,看了一下,真是服了,
    supervisord有一个set_rlimits函数,专门处理这一块的参数, 但supervisord的set_rlimits只会获取系统环境中
    RLIMIT_NOFILE  最大打开文件句柄数
    RLIMIT_NOPROC 用户最大的进程数
    其他全部走python.resource模块设置的默认值, https://pymotw.com/2/resource/
    这一点非常好验证, 直接查看当前系统环境中 max locked memory  和 supervisor进程以及其接管的进程, 明显存在差异
    当然core file size 这个参数也是使用python.resource模块设置的默认值

原因基本上确定下, 解决办法可以尝试 第5步 做法,如果内核不支持, 可以使用下面方法 修改 options.py 1293 下面加入以下代码

soft, hard = resource.getrlimit(resource.RLIMIT_CORE)
resource.setrlimit(resource.RLIMIT_CORE, (-1, hard))

vim  /usr/lib/python2.6/site-packages/supervisor/options.py

        if hasattr(resource, 'RLIMIT_NPROC'):
            limits.append(
                {
                'msg':('The minimum number of available processes required '
                       'to run this program is %(min)s as per the "minprocs" '
                       'command-line argument or config file setting. '
                       'The current environment will only allow you '
                       'to open %(hard)s processes.  Either raise '
                       'the number of usable processes in your '
                       'environment (see README.rst) or lower the '
                       'minprocs setting in the config file to allow '
                       'the program to start.'),
                'min':self.minprocs,
                'resource':resource.RLIMIT_NPROC,
                'name':'RLIMIT_NPROC',
                })

        soft, hard = resource.getrlimit(resource.RLIMIT_CORE)
        resource.setrlimit(resource.RLIMIT_CORE, (-1, hard))

 

转载请注明:爱开源 » supervisord 未生成 core 文件

您必须 登录 才能发表评论!