lsws switch

This commit is contained in:
usmannasir
2018-11-09 22:01:28 +05:00
parent 7f72c84bb1
commit 1c3df3d361
50 changed files with 8430 additions and 1747 deletions

View File

@@ -1,11 +1,15 @@
from CyberCPLogFileWriter import CyberCPLogFileWriter as logging
import subprocess
import shlex
import os
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
class ProcessUtilities:
litespeedProcess = "litespeed"
ent = 1
OLS = 0
centos = 1
ubuntu = 0
@staticmethod
def getLitespeedProcessNumber():
@@ -14,7 +18,7 @@ class ProcessUtilities:
try:
import psutil
for proc in psutil.process_iter():
if proc.name() == ProcessUtilities.litespeedProcess:
if proc.name().find(ProcessUtilities.litespeedProcess) > -1:
finalListOfProcesses.append(proc.pid)
except BaseException,msg:
@@ -30,7 +34,11 @@ class ProcessUtilities:
@staticmethod
def restartLitespeed():
try:
command = "sudo systemctl restart lsws"
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
command = "sudo systemctl restart lsws"
else:
command = "sudo /usr/local/lsws/bin/lswsctrl restart"
cmd = shlex.split(command)
res = subprocess.call(cmd)
@@ -45,7 +53,11 @@ class ProcessUtilities:
@staticmethod
def stopLitespeed():
try:
command = "sudo systemctl stop lsws"
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
command = "sudo systemctl stop lsws"
else:
command = "sudo /usr/local/lsws/bin/lswsctrl stop"
cmd = shlex.split(command)
res = subprocess.call(cmd)
@@ -57,4 +69,58 @@ class ProcessUtilities:
except subprocess.CalledProcessError, msg:
logging.writeToFile(str(msg) + "[stopLitespeed]")
@staticmethod
def executioner(command):
try:
res = subprocess.call(shlex.split(command))
if res == 1:
raise 0
else:
return 1
except BaseException, msg:
return 0
@staticmethod
def killLiteSpeed():
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'
if os.readlink(entPath) == '/usr/local/lsws/bin/lshttpd/openlitespeed':
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
@staticmethod
def executioner(command, statusFile):
try:
res = subprocess.call(shlex.split(command), stdout=statusFile, stderr=statusFile)
if res == 1:
raise 0
else:
return 1
except BaseException, msg:
logging.writeToFile(str(msg))
return 0