openstack L版本neutron server启动分析

本文分析的是OpenStack的L版本neutron server的启动流程
首先看下进程信息
4 S neutron  16698     1  1  80   0 - 97381 ep_pol 22:51 ?        00:00:07 /usr/bin/python2 /usr/bin/neutron-server --config-file /usr/share/neutron/neutron-dist.conf --config-dir /usr/shareneutron/server --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini --config-dir /etc/neutron/conf.d/common --config-dir /etc/neutron/conf.d/neutron-server --log-file /var/log/neutron/server.log
1 S neutron  16740 16698  0  80   0 - 98051 ep_pol 22:51 ?        00:00:00 /usr/bin/python2 /usr/bin/neutron-server --config-file /usr/share/neutron/neutron-dist.conf --config-dir /usr/share/neutron/server --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini --config-dir /etc/neutron/conf.d/common --config-dir /etc/neutron/conf.d/neutron-server --log-file /var/log/neutron/server.log

会发现有两个neutron-server进程,而16740是16698的子进程,具体为什么出现这种情况有待探讨。
从上面信息我们得出,neutron-server的执行入口在/usr/bin/neutron-server看下启动的入口脚本
/usr/bin/neutron-server

import sys

from neutron.cmd.eventlet.server import main_wsgi_eventlet
if __name__ == "__main__":
sys.exit(main_wsgi_eventlet())


~
在看下neutron.cmd.eventlet.server,会发现代码如下
from neutron.server import rpc_eventlet
from neutron.server import wsgi_eventlet
from neutron.server import wsgi_pecan

def main_wsgi_eventlet():
    wsgi_eventlet.main()

# Eventlet patching is not required for Pecan, but some plugins still spawn
# eventlet threads
def main_wsgi_pecan():
    wsgi_pecan.main()

def main_rpc_eventlet():
    rpc_eventlet.main()


接着看下netron.server.wsgi_eventlet
import eventlet
from oslo_log import log
from neutron.i18n import _LI
from neutron import server
from neutron import service
LOG = log.getLogger(__name__)
def _eventlet_wsgi_server():
    pool = eventlet.GreenPool()
    neutron_api = service.serve_wsgi(service.NeutronApiService)
    api_thread = pool.spawn(neutron_api.wait)
    try:
        neutron_rpc = service.serve_rpc()
    except NotImplementedError:
        LOG.info(_LI("RPC was already started in parent process by "
                     "plugin."))
    else:
        rpc_thread = pool.spawn(neutron_rpc.wait)
        plugin_workers = service.start_plugin_workers()
        for worker in plugin_workers:
            pool.spawn(worker.wait)
        # api and rpc should die together.  When one dies, kill the other.
        rpc_thread.link(lambda gt: api_thread.kill())
        api_thread.link(lambda gt: rpc_thread.kill())
    pool.waitall()
def main():
    server.boot_server(_eventlet_wsgi_server)




server.boot_server在server.__init__.py中实现的,具体代码如下
import sys

from oslo_config import cfg

from neutron.common import config


def boot_server(server_func):
    # the configuration will be read into the cfg.CONF global data structure
    config.init(sys.argv[1:])
    config.setup_logging()
    if not cfg.CONF.config_file:
        sys.exit(_("ERROR: Unable to find configuration file via the default"
                   " search paths (~/.neutron/, ~/, /etc/neutron/, /etc/) and"
                   " the '--config-file' option!"))
    try:
        server_func()
    except KeyboardInterrupt:
        pass
    except RuntimeError as e:
        sys.exit(_("ERROR: %s") % e)


所以,代码中的server_func函数就是_eventlet_wsgi_server,后面的分析继续从_eventlet_wsgi_server即可。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

庐山老僧

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值