CO - Bug fixed, kill application

community
Steve L. Nyemba 7 years ago
parent b831586a97
commit 677f037adf

@ -15,6 +15,7 @@ from threading import Thread
import os import os
import shutil import shutil
import subprocess import subprocess
from monitor import ProcessCounter from monitor import ProcessCounter
from utils.transport import QueueListener, QueueWriter, QueueReader from utils.transport import QueueListener, QueueWriter, QueueReader
from utils.params import PARAMS from utils.params import PARAMS
@ -39,13 +40,14 @@ class Actor():
print e print e
return o return o
def __init__(self): def __init__(self):
"""
Initializing the class with configuration. The configuration will be specific to each subclass
@param args arguments the class needs to be configured
"""
pass pass
def getIdentifier(self): def getIdentifier(self):
return self.__class__.__name__.lower() return self.__class__.__name__.lower()
"""
Initializing the class with configuration. The configuration will be specific to each subclass
@param args arguments the class needs to be configured
"""
def init(self,args): def init(self,args):
self.config = args self.config = args
@ -57,23 +59,18 @@ class Actor():
def execute(self,cmd): def execute(self,cmd):
stream = None stream = None
try: try:
subprocess.call (cmd,shell=False) # subprocess.call (cmd,shell=False)
out = subprocess.Popen(cmd,stdout=subprocess.PIPE)
print out
#stream = handler.communicate()[0] #stream = handler.communicate()[0]
except Exception,e: except Exception,e:
pass pass
# def run(self):
# if self.item is not None:
# self.process(self.item)
"""
Sending a message to a queue with parameters to,from,content
"""
def post(self,**args): def post(self,**args):
pass pass
class Apps(Actor) : class Apps(Actor) :
""" """
This class is designed to handle application, restart, if need be. This class is designed to handle application, restart, if need be.
conf{app-name:{args}} conf{app-name:{args}}
""" """
def __init__(self): def __init__(self):
Actor.__init__(self) Actor.__init__(self)
@ -106,7 +103,7 @@ class Apps(Actor) :
app = items[0] app = items[0]
args = self.config[app] args = self.config[app]
cmd = " ".join([app,args,"&"]) cmd = " ".join([app,args,"&" ])
self.execute([app,args]) self.execute([app,args])
print [app,args] print [app,args]
@ -115,9 +112,10 @@ class Apps(Actor) :
kill processes given the name, The function will not be case sensitive and partial names are accepted kill processes given the name, The function will not be case sensitive and partial names are accepted
@NOTE: Make sure the reference to the app is not ambiguous @NOTE: Make sure the reference to the app is not ambiguous
""" """
args = "".join(["ps -eo pid,command|grep -E -i ",name.lower(),'|grep -E "^ {0,}[0-9]+" -o -m 1|xargs kill -9']) args = "".join(['ps -eo pid,command|grep -E -i "',name.lower(),'"|grep -E "^ {0,}[0-9]+" -o|xargs kill -9'])
self.execute([args ]) #self.execute([args])
print args subprocess.call([args],shell=True)
def analyze(self,logs) : def analyze(self,logs) :
""" """
This function is designed to analyze a few logs and take appropriate action This function is designed to analyze a few logs and take appropriate action

Loading…
Cancel
Save