跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. 为OpenERP开发服务器实现自动重启

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

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
3 帖子 2 发布者 4.1k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • 左 离线
    左 离线
    左奕
    写于 最后由 编辑
    #1

    [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 条回复 最后回复
    0
    • C 离线
      C 离线
      ccdos
      写于 最后由 编辑
      #2

      学习了

      1 条回复 最后回复
      0

      • 登录

      • 没有帐号? 注册

      • 登录或注册以进行搜索。
      • 第一个帖子
        最后一个帖子
      0
      • 版块
      • 标签
      • 热门
      • 用户
      • 群组