start_script.py 文件源码

python
阅读 40 收藏 0 点赞 0 评论 0

项目:fuel-ccp-entrypoint 作者: openstack 项目源码 文件源码
def run_daemon(cmd, user=None):
    LOG.info("Starting daemon")
    rendered_cmd = jinja_render_cmd(cmd)
    proc = execute_cmd(rendered_cmd, user)

    # add signal handler
    def sig_handler(signum, frame):
        LOG.info("Caught a signal: %d", signum)
        proc.send_signal(signum)
        if signum == signal.SIGHUP:
            time.sleep(5)
            if proc.poll() is None:
                LOG.info("Service restarted")

    signal.signal(signal.SIGHUP, sig_handler)
    signal.signal(signal.SIGINT, sig_handler)
    signal.signal(signal.SIGTERM, sig_handler)

    # wait for 5 sec and check that process is running
    time.sleep(5)
    if proc.poll() is None:
        LOG.info("Daemon started")
        return proc
    proc.communicate()
    raise RuntimeError("Process exited with code: %d" % proc.returncode)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号