2017-10-24 19:16:36 +05:00
|
|
|
from CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
|
|
|
|
import subprocess
|
2017-12-09 22:30:10 +05:00
|
|
|
import shlex
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProcessUtilities:
|
|
|
|
|
litespeedProcess = "litespeed"
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def getLitespeedProcessNumber():
|
|
|
|
|
finalListOfProcesses = []
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
import psutil
|
|
|
|
|
for proc in psutil.process_iter():
|
|
|
|
|
if proc.name() == ProcessUtilities.litespeedProcess:
|
|
|
|
|
finalListOfProcesses.append(proc.pid)
|
|
|
|
|
|
|
|
|
|
except BaseException,msg:
|
2017-11-09 00:35:52 +05:00
|
|
|
logging.writeToFile(
|
2017-10-24 19:16:36 +05:00
|
|
|
str(msg) + " [getLitespeedProcessNumber]")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
if len(finalListOfProcesses) > 0:
|
|
|
|
|
return finalListOfProcesses
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def restartLitespeed():
|
|
|
|
|
try:
|
2017-12-09 22:30:10 +05:00
|
|
|
command = "sudo systemctl restart lsws"
|
|
|
|
|
cmd = shlex.split(command)
|
|
|
|
|
res = subprocess.call(cmd)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2017-12-09 22:30:10 +05:00
|
|
|
if res == 0:
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2017-12-09 22:30:10 +05:00
|
|
|
except subprocess.CalledProcessError,msg:
|
2017-10-24 19:16:36 +05:00
|
|
|
logging.writeToFile(str(msg) + "[restartLitespeed]")
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def stopLitespeed():
|
|
|
|
|
try:
|
2017-12-09 22:30:10 +05:00
|
|
|
command = "sudo systemctl stop lsws"
|
|
|
|
|
cmd = shlex.split(command)
|
|
|
|
|
res = subprocess.call(cmd)
|
|
|
|
|
|
|
|
|
|
if res == 0:
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
|
2017-10-24 19:16:36 +05:00
|
|
|
except subprocess.CalledProcessError, msg:
|
|
|
|
|
logging.writeToFile(str(msg) + "[stopLitespeed]")
|
|
|
|
|
|
|
|
|
|
|