Improve Nginx service management

This commit is contained in:
VirtuBox
2019-08-27 12:32:48 +02:00
parent 378c9a4820
commit c60d4e306a
5 changed files with 40 additions and 20 deletions

View File

@@ -1,5 +1,4 @@
"""WordOps Service Manager"""
import os
import subprocess
from wo.core.logging import Log
@@ -23,10 +22,14 @@ class WOService():
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
if retcode[0] == 0:
Log.info(self, "Starting Nginx" +
"[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
return True
else:
Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE+"]")
Log.info(
self, "Starting Nginx" + "[" + Log.FAIL +
"Failed" + Log.OKBLUE+"]")
return False
else:
service_cmd = ('service {0} start'.format(service_name))
@@ -78,12 +81,16 @@ class WOService():
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
if retcode[0] == 0:
Log.info(self, "Restarting Nginx" +
"[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
return True
else:
Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE+"]")
Log.info(
self, "Restarting Nginx" + "[" + Log.FAIL +
"Failed" + Log.OKBLUE+"]")
return False
else:
service_cmd = ('service {0} restart'.format(service_name))
@@ -113,17 +120,19 @@ class WOService():
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))
service_cmd = ('service {0} reload'.format(service_name))
retcode = subprocess.getstatusoutput(service_cmd)
Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
return True
if retcode[0] == 0:
Log.info(self, "Reloading Nginx" +
"[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
return True
else:
Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE+"]")
Log.info(
self, "Restarting Nginx" + "[" + Log.FAIL +
"Failed" + Log.OKBLUE+"]")
return False
else:
service_cmd = ('service {0} reload'.format(service_name))
Log.info(self, "Reload : {0:10}".format(service_name), end='')
retcode = subprocess.getstatusoutput(service_cmd)
if retcode[0] == 0: