Browse Source

Added check service config before restart/start

stable
gau1991 10 years ago
parent
commit
22a4f73415
  1. 43
      ee/core/services.py

43
ee/core/services.py

@ -18,9 +18,14 @@ class EEService():
Similar to `service xyz start` Similar to `service xyz start`
""" """
try: try:
if service_name in ['nginx', 'php5-fpm']:
service_cmd = ('{0} -t && service {0} start'
.format(service_name))
else:
service_cmd = ('service {0} start'.format(service_name))
Log.info(self, "Start : {0:10}" .format(service_name), end='') Log.info(self, "Start : {0:10}" .format(service_name), end='')
retcode = subprocess.getstatusoutput('service {0} start' retcode = subprocess.getstatusoutput(service_cmd)
.format(service_name))
if retcode[0] == 0: if retcode[0] == 0:
Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]") Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
return True return True
@ -60,9 +65,14 @@ class EEService():
Similar to `service xyz restart` Similar to `service xyz restart`
""" """
try: try:
if service_name in ['nginx', 'php5-fpm']:
service_cmd = ('{0} -t && service {0} restart'
.format(service_name))
else:
service_cmd = ('service {0} restart'.format(service_name))
Log.info(self, "Restart : {0:10}".format(service_name), end='') Log.info(self, "Restart : {0:10}".format(service_name), end='')
retcode = subprocess.getstatusoutput('service {0} restart' retcode = subprocess.getstatusoutput(service_cmd)
.format(service_name))
if retcode[0] == 0: if retcode[0] == 0:
Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]") Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
return True return True
@ -82,26 +92,13 @@ class EEService():
""" """
try: try:
if service_name in ['nginx', 'php5-fpm']: if service_name in ['nginx', 'php5-fpm']:
Log.info(self, "Reload : {0:10}".format(service_name), service_cmd = ('{0} -t && service {0} reload'
end='') .format(service_name))
retcode = subprocess.getstatusoutput('{0} -t &&' else:
' service {0} reload' service_cmd = ('service {0} reload'.format(service_name))
.format(service_name))
if retcode[0] == 0:
# print(retcode[0])
# subprocess.getstatusoutput('service {0} reload'
# .format(service_name))
Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE +
"]")
return True
else:
Log.debug(self, "{0}".format(retcode[1]))
Log.info(self, "[" + Log.FAIL + "Failed" +
Log.OKBLUE+"]")
return False
Log.info(self, "Reload : {0:10}".format(service_name), end='') Log.info(self, "Reload : {0:10}".format(service_name), end='')
retcode = subprocess.getstatusoutput('service {0} reload' retcode = subprocess.getstatusoutput(service_cmd)
.format(service_name))
if retcode[0] == 0: if retcode[0] == 0:
Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]") Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
return True return True

Loading…
Cancel
Save