odoo17后台启动过程2——odoo_bin server子命令

在前一篇文章中,我们介绍了odoo_bin脚手架的实现原理,重点是Command元类。今天我们来看看server 子命令式怎么实现的,server子命令的实现类在:
odoo\cli\server.py

class Server(Command):
    """Start the odoo server (default command)"""
    def run(self, args):
        odoo.tools.config.parser.prog = f'{Path(sys.argv[0]).name} {self.name}'
        main(args)

Server类继承了Command父类,并实现了run方法。

 odoo.tools.config.parser.prog = f'{Path(sys.argv[0]).name} {self.name}'
 这一句的结果是odoo-bin server

run方法调用了main方法。

def main(args):
    check_root_user()
    odoo.tools.config.parse_config(args)
    check_postgres_user()
    report_configuration()

    config = odoo.tools.config

    # the default limit for CSV fields in the module is 128KiB, which is not
    # quite sufficient to import images to store in attachment. 500MiB is a
    # bit overkill, but better safe than sorry I guess
    csv.field_size_limit(500 * 1024 * 1024)

    preload = []
    if config['db_name']:
        preload = config['db_name'].split(',')
        for db_name in preload:
            try:
                odoo.service.db._create_empty_database(db_name)
                config['init']['base'] = True
            except ProgrammingError as err:
                if err.pgcode == errorcodes.INSUFFICIENT_PRIVILEGE:
                    # We use an INFO loglevel on purpose in order to avoid
                    # reporting unnecessary warnings on build environment
                    # using restricted database access.
                    _logger.info("Could not determine if database %s exists, "
                                 "skipping auto-creation: %s", db_name, err)
                else:
                    raise err
            except odoo.service.db.DatabaseExists:
                pass

    if config["translate_out"]:
        export_translation()
        sys.exit(0)

    if config["translate_in"]:
        import_translation()
        sys.exit(0)

    # This needs to be done now to ensure the use of the multiprocessing
    # signaling mechanism for registries loaded with -d
    if config['workers']:
        odoo.multi_process = True

    stop = config["stop_after_init"]

    setup_pid_file()
    rc = odoo.service.server.start(preload=preload, stop=stop)
    sys.exit(rc)

做了几件事:
1、检测系统用户是否为root,如果是root,则报一个预警(注意不是退出)
2、解析参数
3、检测pg用户,如果是postgres管理员账号, 报警,退出。
4、打印配置信息

2024-01-02 09:08:42,249 5180 INFO ? odoo: database: odoo@127.0.0.1:5432 

5、获取到config对象
这个config对象的信息从下面连个渠道而来:
1)、odoo.conf 配置文件
2)、命令行参数

6、根据配置文件中指定的数据库名创建数据库并初始化,如果数据库已经存在,则报一个异常
从这里可以得出一个结论,那就是我们可以在配置文件中指定一个不存在的数据库,odoo自动会帮我们创建并初始化。
7、启动服务

odoo.service.server.start(preload=preload, stop=stop)

这篇文章就介绍到这,下一篇文章介绍service下的server.py文件,里面定义了三种server,包括我们最常用的ThreadServer。

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值