Skip to main content
 首页 » 编程设计

python之使用 systemctl 重新启动和更新 Odoo 服务

2025年01月19日9飞鱼

Odoo服务由systemctl start odoo启动。我正在使用 Centos。当我想更新更改后的 *.py 代码时,我曾经这样做:

1. systemctl stop odoo 
Then I update my module and database by useing this: 
2. ./odoo.py -c openerp-server.conf -u <my_module_name> -d <database_name> 
3. stop service by ctrl + c 
4. systemctl start odoo 

但更新更改的方式真的很长而且不舒服。

是否有更短的方法以更短的方式完成相同的操作?

请您参考如下方法:

Odoo 服务

您可以像这样进行更改:

  1. 停止服务器:systemctl stop odoo
  2. 启动服务器:systemctl start odoo。这里更新了 .py
  3. 如果您还需要更新 xml 或一些翻译,您可以在 Odoo 界面的模块描述表单上按 Update 按钮。

注意:有一些模块可以重新加载特定的 xml View 。如果您对此感兴趣,我可以看看是否找到了。

没有服务的 Odoo

如果您在本地计算机上进行开发,则不需要使用 systemctl。只需使用 odoo.py 直接运行 Odoo,您就可以立即看到更改:

./odoo.py -c openerp-server.conf -u <my_module_name> -d <database_name> 

自动重新加载 Python 文件

还有一个选项可以在 python 文件发生变化时重新加载它们。检查这个other answer :

Normally if you change your python code means, you need to restart the server in order to apply the new changes.

--auto-reload parameter is enabled means, you don't need to restart the server. It enables auto-reloading of python files and xml files without having to restart the server. It required pyinotify. It is a Python module for monitoring filesystems changes.

Just add --auto-reload in your configuration file. By default the value will be "false". You don't need to pass any extra arguments. --auto-reload is enough. If everything setup and works properly you will get

openerp.service.server: Watching addons folder /opt/odoo/v8.0/addons 
openerp.service.server: AutoReload watcher running in the server log. Don't forget to install pyinotify package. 

但在 odoo 10 中只需添加 --dev=reload 参数

--dev=DEV_MODE      Enable developer mode. Param: List of options 
                    separated by comma. Options : all, 
                    [pudb|wdb|ipdb|pdb], reload, qweb, werkzeug, xml