Example #1
0
def makeService(config):
  clientService = service.MultiService()
  changeDpDir(config['dataDir'])
  process.initYaml()
  process.startAll('first')
  looping.start(process.PERIOD)
  internet.TCPClient(config['server'],int(config['port']), CoreClientFactory(config)).setServiceParent(clientService)
  def shutdown():
    process.stopAll()
  reactor.addSystemEventTrigger("before", "shutdown", shutdown)
  return clientService
Example #2
0
 def _processJson(self,json):
   action = json.get('action')
   if action=='clientOp':
     value = json['value']
     if value=='Restart':
       reactor.stop()
     elif value=='Update':
       downloadFiles(self.config,selfFileSet)
     elif value=='Reload':
       process.initYaml()
       process.startAll('reload')
       self._initSend()
     else:
       print 'unknown clientOp value:'+value
   elif action=='procOp':
     psGroup = json['grp']
     psName = json['name']
     op = json['op']
     if op=='Restart':
       process.restartProc(psGroup,psName,memo='manual')
     elif op=='Update':
       self._updateProc(psGroup,psName)
     elif op=='Console':
       self.sendLogTxt(json['uuid'],*(process.getPsLog(psGroup,psName,json.get('startPos'),json.get('endPos'))))
     elif op=='Log':
       self.sendLogTxt(json['uuid'],*(process.getPsLog(psGroup,psName,json.get('startPos'),json.get('endPos'),logType='log')))
     elif op=='StartHistory':
       self.sendLogTxt(json['uuid'],*(process.getPsLog(psGroup,psName,json.get('startPos'),json.get('endPos'),logType='start')))
     elif op=='UpdateHistory':
       self.sendLogTxt(json['uuid'],*(process.getPsLog(psGroup,psName,json.get('startPos'),json.get('endPos'),logType='update')))
     else:
       print 'unknown procOp value:'+op
   elif action=='groupOp':
     psGroup = json['grp']
     op = json['op']
     if op=='Restart':
       pg = procGroupDict.get(psGroup)
       if pg:
         for name,proc in pg.iterStatus():
           pg.restartProc(name,memo='group')
       else:
         print 'restart group,can not found process group:'+psGroup
     elif op=='Update':
       pg = procGroupDict.get(psGroup)
       if pg:
         for name,proc in pg.iterStatus():
           self._updateProc(psGroup,name)
       else:
         print 'update group,can not found process group:'+psGroup
   else:
     print 'unknown json %s'%json