zoukankan      html  css  js  c++  java
  • [python基础]xml_rpc远程调控supervisor节点进程

    supervisor提供的两种管理方式,supervisorctl和web其实都是通过xml_rpc来实现的。

    xml_rpc其实就是本地可以去调用远端的函数方法,在python中只需要引入xmlrpclib即可实现对客户端的操作

    例如:

    import xmlrpclib
    server = xmlrpclib.server('http://localhost:9001/RPC2')
    methods = server.system.listMethods()
    print(methods)

    结果如下:

    ['supervisor.addProcessGroup', 'supervisor.clearAllProcessLogs', 'supervisor.clearLog', 'supervisor.clearProcessLog', 

    'supervisor.clearProcessLogs', 'supervisor.getAPIVersion', 'supervisor.getAllConfigInfo', 'supervisor.getAllProcessInfo',

    'supervisor.getIdentification', 'supervisor.getPID', 'supervisor.getProcessInfo', 'supervisor.getState', 'supervisor.getSupervisorVersion',

    'supervisor.getVersion', 'supervisor.readLog', 'supervisor.readMainLog', 'supervisor.readProcessLog', 'supervisor.readProcessStderrLog',

    'supervisor.readProcessStdoutLog', 'supervisor.reloadConfig', 'supervisor.removeProcessGroup', 'supervisor.restart', 'supervisor.sendProcessStdin',

    'supervisor.sendRemoteCommEvent', 'supervisor.shutdown', 'supervisor.signalAllProcesses', 'supervisor.signalProcess', 'supervisor.signalProcessGroup',

    'supervisor.startAllProcesses', 'supervisor.startProcess', 'supervisor.startProcessGroup', 'supervisor.stopAllProcesses', 'supervisor.stopProcess',

    'supervisor.stopProcessGroup', 'supervisor.tailProcessLog', 'supervisor.tailProcessStderrLog', 'supervisor.tailProcessStdoutLog',

    'system.listMethods', 'system.methodHelp', 'system.methodSignature', 'system.multicall']

    所有方法在/Library/Python/2.7/site-packages/supervisor/rpcinterface.py下

    举个例子:

    1.启动该节点下某个程序:
    if
    server.supervisor.startProcess(process_name): print('%s has started' %process_name)

    如果该程序已经启动会报错:

      xmlrpclib.Fault: <Fault 60: 'ALREADY_STARTED: celery_beat'>

      2.停止某个程序

    server.supervisor.stopProcess(process_name)

     如果该程序未启动则会报错:

      xmlrpclib.Fault: <Fault 70: 'NOT_RUNNING: celery_beat'>

      3.读取日志

      og = server.supervisor.readLog(0,500)

      print(log)

    结果如下:

    2018-09-14 17:31:25,782 INFO RPC interface 'supervisor' initialized
    2018-09-14 17:31:25,782 CRIT Server 'inet_http_server' running without any HTTP authentication checking
    2018-09-14 17:31:25,785 INFO daemonizing the supervisord process
    2018-09-14 17:31:25,786 INFO supervisord started with pid 51752
    2018-09-14 17:31:58,968 INFO spawned: 'django_web' with pid 51757
    2018-09-14 17:32:00,512 INFO success: django_web entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
    2018-0

    4.关闭某个supervisor节点
    server.supervisor.shutdown()
    此时如果再用xmlrpclib创建server会报错:

      socket.error: [Errno 61] Connection refused

    完。

  • 相关阅读:
    document.getElementById(“id”)与$("#id")的区别
    sqlserver 无法打开备份文件a.bak
    xnconvert 图片转换工具
    基于jQuery的 h5移动端抽奖页面插件
    nodeJS 简单启动express服务器
    jquery 按钮切换插件
    微信判断手机有没有APP,有则打开,没有则跳到应用商城
    jQuery 文字向上轮播
    Node.js制作爬取简书内容的爬虫
    jquery手机端轮播图,点击放大手动轮播
  • 原文地址:https://www.cnblogs.com/halleluyah/p/9674584.html
Copyright © 2011-2022 走看看