【问题标题】:Remote controller for python processespython进程的远程控制器
【发布时间】:2015-09-07 06:32:05
【问题描述】:

我有两个Twitter Streaming APIs 在一台机器上运行,它们都是python 进程并在supervisor 上运行。我想设计一个控制器,它可以根据命令停止/启动/重新启动这两个进程。

一种方法是在该机器上公开一个 Web API,并在需要更改状态时访问该 URL。可以使用subprocess重启Supervisord。

我正在阅读Pyro,这似乎是一个解决方案,可以消除上述步骤中对 API 系统的需求。

我缺少什么或任何其他解决方案是对这两者的升级吗?

【问题讨论】:

    标签: python ubuntu subprocess monitoring supervisord


    【解决方案1】:

    我很确定主管可以为您做到这一点,看看这个

    http://supervisord.org/api.html

    Supervisor包含一个xml rpc来控制它下的进程,你只需要配置它。查看文档和本指南

    http://devo.ps/blog/using-supervisord-for-your-deploy-pipelines/

    他在那里配置rpc接口

    【讨论】:

      【解决方案2】:

      正如您提到的,我将公开一个使用 CherryPy 作为守护程序运行的 REST api。 它更简单,您唯一需要控制的是请求。如果需要,您可以添加参数,然后通过其他一些请求使内容更加丰富。此外,您可以在 Windows 中将其用作 Windows 服务。 https://cherrypy.readthedocs.org/en/3.2.6/refman/process/plugins/daemonizer.html

      【讨论】:

        【解决方案3】:

        集群管理工具非常适合此类用例。您获得的好处是,当您拥有多台机器时,该解决方案甚至可以工作。 检查 ansible supervisor 插件,例如: http://docs.ansible.com/ansible/supervisorctl_module.html

        您只需要从运行 ansible 的远程机器调用命令,因为它是无代理的,它会处理其余的事情。请参阅下面我为类似内容编写的剧本:

            ---
            - hosts: webservers
              user: admin
              sudo: yes
              sudo_user: root
              vars:
                node_env: "{{ DEPLOY_ENV|default(staging) }}"
              vars_files:
                - ../vars/secret
                - ../vars/main.yml
                - ../defaults/main.yml
        
              tasks:
        
              # Manage Supervisor web tasks - restart them in a specific order
              - name: Restart Data API supervisor Job
                supervisorctl: name="web:data_api" state=restarted
              - name: Restart Data API-2 supervisor Job
                supervisorctl: name="web:data_api2" state=restarted
        
              handlers:
               - name: test all
                 shell: source /etc/profile.d/go-api.sh && source /etc/profile.d/go-path.sh && source /etc/profile.d/go-bin.sh && cd /opt/go/src/github.com/pgaref/data_api && go test . ./... executable=/bin/bash
                 shell: source /etc/profile.d/go-api.sh && source /etc/profile.d/go-path.sh && source /etc/profile.d/go-bin.sh && cd /opt/go/src/github.com/pgaref/data_api2 && go test . ./... executable=/bin/bash
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-02-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-04-09
          • 2011-12-12
          • 2015-05-19
          相关资源
          最近更新 更多