Odoo中文社区可以通过以下三个域名访问:shine-it.net , odoocn.org,odoo.net.cn

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

为OpenERP开发服务器实现自动重启



  • [b]注明(非常重要): 此方案并未在生产环境测试,未经过充分测试的条件下,请勿使用在生产环境.[/b]

    很多Web或Server框架都会实现一个可以自动检测文件修改后自动重启服务器的测试服务器.很遗憾OpenERP并没有提供这个功能.
    那我们就来自己实现一个.(注: 实现原理非原创,copy至django开发服务器.)


    大概说一下实现原理:
    自动重启服务器采用多进程方式实现.
    1) 主进程负责启动子进程,检测子进程是否退出,及子进程返回的退出状态. 如果子进程返回的状态是需要重启,则重启子进程.
    2) 子进程负责启动OpenERP Server,及检测py文件是否更改.如果py文件已更改,则停止自身,并返回重启状态的新号给主进程.

    原openerp-server.py中需要修改部分代码,因为openerp-server原本采用信号机制监听停止命令,但是子进程并不支持信号机制.所以改为监听KeyboardInterrupt异常.

    <br /># modify by xuwb start<br />#LST_SIGNALS = &#91;&#039;SIGINT&#039;, &#039;SIGTERM&#039;]<br />#if os.name == &#039;posix&#039;:<br />&nbsp; &nbsp; #LST_SIGNALS.extend(&#91;&#039;SIGUSR1&#039;,&#039;SIGQUIT&#039;])<br /><br /><br />#SIGNALS = dict(<br />&nbsp; &nbsp; #[(getattr(signal, sign), sign) for sign in LST_SIGNALS]<br />#)<br /><br />#def handler(signum, _):<br />&nbsp; &nbsp; #&quot;&quot;&quot;<br />&nbsp; &nbsp; #:param signum: the signal number<br />&nbsp; &nbsp; #:param _: <br />&nbsp; &nbsp; #&quot;&quot;&quot;<br />&nbsp; &nbsp; #if tools.config&#91;&#039;netrpc&#039;]:<br />&nbsp; &nbsp; &nbsp; &nbsp; #tinySocket.stop()<br />&nbsp; &nbsp; #if tools.config&#91;&#039;xmlrpc&#039;]:<br />&nbsp; &nbsp; &nbsp; &nbsp; #httpd.stop()<br />&nbsp; &nbsp; #netsvc.Agent.quit()<br />&nbsp; &nbsp; #if tools.config&#91;&#039;pidfile&#039;]:<br />&nbsp; &nbsp; &nbsp; &nbsp; #os.unlink(tools.config&#91;&#039;pidfile&#039;])<br />&nbsp; &nbsp; #logger.notifyChannel(&#039;shutdown&#039;, netsvc.LOG_INFO, <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  #&quot;Shutdown Server! - %s&quot; % ( SIGNALS[signum], ))<br />&nbsp; &nbsp; #logger.shutdown()<br />&nbsp; &nbsp; #sys.exit(0)<br /><br />#for signum in SIGNALS:<br />&nbsp; &nbsp; #signal.signal(signum, handler)<br /># modify by xuwb end<br /><br /># modify by xuwb start <br />#while True:<br />&nbsp; &nbsp; #time.sleep(1)<br /># modify by xuwb end
    



    新增代码:

    <br />try:<br />&nbsp; &nbsp; while True:<br />&nbsp; &nbsp; &nbsp; &nbsp; time.sleep(1)<br />except KeyboardInterrupt:<br />&nbsp; &nbsp; print &#039;Shutdown server ... add by xuwb&#039;<br />&nbsp; &nbsp; if tools.config&#91;&#039;netrpc&#039;]:<br />&nbsp; &nbsp; &nbsp; &nbsp; tinySocket.stop()<br />&nbsp; &nbsp; if tools.config&#91;&#039;xmlrpc&#039;]:<br />&nbsp; &nbsp; &nbsp; &nbsp; httpd.stop()<br />&nbsp; &nbsp; netsvc.Agent.quit()<br />&nbsp; &nbsp; if tools.config&#91;&#039;pidfile&#039;]:<br />&nbsp; &nbsp; &nbsp; &nbsp; os.unlink(tools.config&#91;&#039;pidfile&#039;])<br />&nbsp; &nbsp; logger.notifyChannel(&#039;shutdown&#039;, netsvc.LOG_INFO, <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &quot;Shutdown Server! - %s&quot; % ( SIGNALS[signum], ))<br />&nbsp; &nbsp; logger.shutdown()<br />&nbsp; &nbsp; sys.exit(0)<br />
    



    在启动server时,需要更换为执行 openerp-server-autoreload.py文件.

    需要将附件中3个文件放置在${OPENERP_SERVER}/bin目录下.(注: 我使用的openerp-server.py文件的版本是5.0.10.如果不是此版本,请对openerp-server.py执行上述修改.)
    祝各位看官,开发愉快 ... ^_^



  • 学习了