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
|
2018-11-09 22:01:28 +05:00
|
|
|
import os
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
class ProcessUtilities:
|
|
|
|
|
litespeedProcess = "litespeed"
|
2018-11-09 22:01:28 +05:00
|
|
|
ent = 1
|
|
|
|
|
OLS = 0
|
|
|
|
|
centos = 1
|
|
|
|
|
ubuntu = 0
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def getLitespeedProcessNumber():
|
|
|
|
|
finalListOfProcesses = []
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
import psutil
|
|
|
|
|
for proc in psutil.process_iter():
|
2018-11-09 22:01:28 +05:00
|
|
|
if proc.name().find(ProcessUtilities.litespeedProcess) > -1:
|
2017-10-24 19:16:36 +05:00
|
|
|
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:
|
2018-11-09 22:01:28 +05:00
|
|
|
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
|
|
|
|
|
command = "sudo systemctl restart lsws"
|
|
|
|
|
else:
|
|
|
|
|
command = "sudo /usr/local/lsws/bin/lswsctrl restart"
|
|
|
|
|
|
2017-12-09 22:30:10 +05:00
|
|
|
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:
|
2018-11-09 22:01:28 +05:00
|
|
|
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
|
|
|
|
|
command = "sudo systemctl stop lsws"
|
|
|
|
|
else:
|
|
|
|
|
command = "sudo /usr/local/lsws/bin/lswsctrl stop"
|
|
|
|
|
|
2017-12-09 22:30:10 +05:00
|
|
|
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]")
|
|
|
|
|
|
2018-11-09 22:01:28 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def executioner(command):
|
|
|
|
|
try:
|
|
|
|
|
res = subprocess.call(shlex.split(command))
|
2018-12-06 15:03:43 +05:00
|
|
|
if res == 0:
|
2018-11-09 22:01:28 +05:00
|
|
|
return 1
|
2018-12-06 15:03:43 +05:00
|
|
|
else:
|
|
|
|
|
return 0
|
2018-11-09 22:01:28 +05:00
|
|
|
except BaseException, msg:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def killLiteSpeed():
|
2018-11-10 16:05:40 +05:00
|
|
|
try:
|
|
|
|
|
command = 'sudo systemctl stop lsws'
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
2018-11-09 22:01:28 +05:00
|
|
|
pids = ProcessUtilities.getLitespeedProcessNumber()
|
|
|
|
|
if pids !=0:
|
|
|
|
|
for items in pids:
|
|
|
|
|
try:
|
|
|
|
|
command = 'sudo kill -9 ' + str(items)
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def decideServer():
|
|
|
|
|
entPath = '/usr/local/lsws/bin/lshttpd'
|
|
|
|
|
|
2018-11-10 02:37:45 +05:00
|
|
|
if os.path.exists('/usr/local/lsws/bin/openlitespeed'):
|
2018-11-09 22:01:28 +05:00
|
|
|
return ProcessUtilities.OLS
|
|
|
|
|
else:
|
|
|
|
|
return ProcessUtilities.ent
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def decideDistro():
|
|
|
|
|
distroPath = '/etc/lsb-release'
|
|
|
|
|
|
|
|
|
|
if os.path.exists(distroPath):
|
|
|
|
|
return ProcessUtilities.ubuntu
|
|
|
|
|
else:
|
|
|
|
|
return ProcessUtilities.centos
|
|
|
|
|
|
|
|
|
|
|
2017-10-24 19:16:36 +05:00
|
|
|
|