Fix nginx restart service

This commit is contained in:
VirtuBox
2019-08-27 10:20:25 +02:00
parent b9d9969093
commit 378c9a4820

View File

@@ -1,10 +1,9 @@
"""WordOps Service Manager"""
import os
import subprocess
from subprocess import Popen
from wo.core.logging import Log
class WOService():
"""Intialization for service"""
def ___init__():
@@ -16,13 +15,19 @@ class WOService():
Similar to `service xyz start`
"""
try:
if service_name in ['nginx', 'php5-fpm']:
if service_name in ['nginx']:
# Check Nginx configuration before executing command
sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
output, error_output = sub.communicate()
if 'emerg' not in str(error_output):
service_cmd = ('service {0} start'.format(service_name))
retcode = subprocess.getstatusoutput(service_cmd)
Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
return True
else:
Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE+"]")
return False
else:
service_cmd = ('service {0} start'.format(service_name))
@@ -67,16 +72,21 @@ class WOService():
Similar to `service xyz restart`
"""
try:
if service_name in ['nginx', 'php5-fpm']:
if service_name in ['nginx']:
# Check Nginx configuration before executing command
sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
output, error_output = sub.communicate()
if 'emerg' not in str(error_output):
Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
service_cmd = ('service {0} restart'.format(service_name))
retcode = subprocess.getstatusoutput(service_cmd)
return True
else:
Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE+"]")
return False
else:
service_cmd = ('service {0} restart'.format(service_name))
Log.info(self, "Restart : {0:10}".format(service_name), end='')
retcode = subprocess.getstatusoutput(service_cmd)
if retcode[0] == 0:
@@ -97,13 +107,20 @@ class WOService():
Similar to `service xyz stop`
"""
try:
if service_name in ['nginx', 'php5-fpm']:
if service_name in ['nginx']:
# Check Nginx configuration before executing command
sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
output, error_output = sub.communicate()
if 'emerg' not in str(error_output):
service_cmd = ('service {0} restart'.format(service_name))
retcode = subprocess.getstatusoutput(service_cmd)
Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
return True
else:
Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE+"]")
return False
else:
service_cmd = ('service {0} reload'.format(service_name))