Navigation

    Odoo 中文社区

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Popular
    • Users
    • Groups

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

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

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

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

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

    Odoo 开发与实施交流
    2
    3
    3869
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • 左
      左奕 last edited by

      [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执行上述修改.)
      祝各位看官,开发愉快 ... ^_^

      1 Reply Last reply Reply Quote 0
      • C
        ccdos last edited by

        学习了

        1 Reply Last reply Reply Quote 0
        • First post
          Last post