python 个进程的远程控制器

Remote controller for python processes

我在一台机器上有两个 Twitter Streaming APIs 运行,它们都是 python 进程,运行 在 supervisor 上。我想设计一个控制器,可以on command,stop/start/restart两个进程。

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

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

我遗漏了什么或任何其他解决方案是对这两个的升级?

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

http://supervisord.org/api.html

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

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

他在那里配置rpc接口

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

集群管理工具非常适合这样的用例。您获得的好处是,即使您拥有多台机器,该解决方案也能正常工作。 检查 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