|
@ -4,6 +4,7 @@ import sys |
|
|
import subprocess |
|
|
import subprocess |
|
|
from subprocess import Popen |
|
|
from subprocess import Popen |
|
|
from ee.core.logging import Log |
|
|
from ee.core.logging import Log |
|
|
|
|
|
import pystache |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EEService(): |
|
|
class EEService(): |
|
@ -17,13 +18,13 @@ class EEService(): |
|
|
retcode = subprocess.getstatusoutput('service {0} start' |
|
|
retcode = subprocess.getstatusoutput('service {0} start' |
|
|
.format(service_name)) |
|
|
.format(service_name)) |
|
|
if retcode[0] == 0: |
|
|
if retcode[0] == 0: |
|
|
Log.info(self, "Started : {0} [ok]" |
|
|
Log.info(self, "Started : {0:10}{1}" |
|
|
.format(service_name)) |
|
|
.format(service_name, "[OK]")) |
|
|
else: |
|
|
else: |
|
|
Log.error(self, retcode[1]) |
|
|
Log.error(self, retcode[1]) |
|
|
except OSError as e: |
|
|
except OSError as e: |
|
|
Log.error(self, "Failed to start service {0} {1} [FAIL]" |
|
|
Log.error(self, "Failed to start service {0} {1} {2}" |
|
|
.format(e.errno, e.strerror)) |
|
|
.format(e.errno, e.strerror, "[FAIL]")) |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
def stop_service(self, service_name): |
|
|
def stop_service(self, service_name): |
|
@ -31,25 +32,25 @@ class EEService(): |
|
|
retcode = subprocess.getstatusoutput('service {0} stop' |
|
|
retcode = subprocess.getstatusoutput('service {0} stop' |
|
|
.format(service_name)) |
|
|
.format(service_name)) |
|
|
if retcode[0] == 0: |
|
|
if retcode[0] == 0: |
|
|
Log.info(self, "Stopped : {0} [OK]" |
|
|
Log.info(self, "Stopped : {0:10}{1}" |
|
|
.format(service_name)) |
|
|
.format(service_name, "[OK]")) |
|
|
return True |
|
|
return True |
|
|
else: |
|
|
else: |
|
|
return False |
|
|
return False |
|
|
except OSError as e: |
|
|
except OSError as e: |
|
|
Log.error(self, "Failed to stop service : {0}{1} [FAIL]" |
|
|
Log.error(self, "Failed to stop service : {0}{1}{2}" |
|
|
.format(e.errno, e.strerror)) |
|
|
.format(e.errno, e.strerror, "[FAIL]")) |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
def restart_service(self, service_name): |
|
|
def restart_service(self, service_name): |
|
|
try: |
|
|
try: |
|
|
EEService.stop_service(self, service_name) |
|
|
EEService.stop_service(self, service_name) |
|
|
EEService.start_service(self, service_name) |
|
|
EEService.start_service(self, service_name) |
|
|
Log.info(self, "restart : {0} [OK]" |
|
|
Log.info(self, "restart : {0:10}{1}" |
|
|
.format(service_name)) |
|
|
.format(service_name, "[OK]")) |
|
|
except OSError as e: |
|
|
except OSError as e: |
|
|
Log.error(self, "Failed to restart services \{0} {1} [FAIL]" |
|
|
Log.error(self, "Failed to restart services \{0} {1} {2}" |
|
|
.format(e.errno, e.strerror)) |
|
|
.format(e.errno, e.strerror, "[FAIL]")) |
|
|
|
|
|
|
|
|
def reload_service(self, service_name): |
|
|
def reload_service(self, service_name): |
|
|
try: |
|
|
try: |
|
@ -59,34 +60,32 @@ class EEService(): |
|
|
if retcode[0] == 0: |
|
|
if retcode[0] == 0: |
|
|
subprocess.getstatusoutput('service {0} reload' |
|
|
subprocess.getstatusoutput('service {0} reload' |
|
|
.format(service_name)) |
|
|
.format(service_name)) |
|
|
Log.info(self, "reload : {0} [OK]" |
|
|
Log.info(self, "reload : {0} {0:10}" |
|
|
.format(service_name)) |
|
|
.format(service_name, "[OK]")) |
|
|
return True |
|
|
return True |
|
|
else: |
|
|
else: |
|
|
Log.error(self, "reload : {0} [FAIL]" |
|
|
Log.error(self, "reload : {0}{1}" |
|
|
.format(service_name)) |
|
|
.format(service_name, "[FAIL]")) |
|
|
Log.debug("{0}" |
|
|
Log.debug("{0}".format(retcode[1])) |
|
|
.format(retcode[1])) |
|
|
|
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
retcode = subprocess.getstatusoutput('service {0} reload' |
|
|
retcode = subprocess.getstatusoutput('service {0} reload' |
|
|
.format(service_name)) |
|
|
.format(service_name)) |
|
|
if retcode[0] == 0: |
|
|
if retcode[0] == 0: |
|
|
Log.info(self, "reload : {0} [OK]" |
|
|
Log.info(self, "reload : {0:10}{1}" |
|
|
.format(service_name)) |
|
|
.format(service_name, "[OK]")) |
|
|
return True |
|
|
return True |
|
|
else: |
|
|
else: |
|
|
return False |
|
|
return False |
|
|
except OSError as e: |
|
|
except OSError as e: |
|
|
|
|
|
Log.error(self, "Failed to reload {0} {1} {2}" |
|
|
Log.error(self, "Failed to reload {0} {1} [FAIL]" |
|
|
.format(service_name, e, "[FAIL]")) |
|
|
.format(service_name, e)) |
|
|
sys.exit(1) |
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
|
|
|
def get_service_status(self, service_name): |
|
|
def get_service_status(self, service_name): |
|
|
try: |
|
|
try: |
|
|
is_exist = subprocess.getstatusoutput('which {0}' |
|
|
is_exist = subprocess.getstatusoutput('which {0}' |
|
|
.format(service_name))[0] |
|
|
.format(service_name)) |
|
|
if is_exist == 0: |
|
|
if is_exist == 0: |
|
|
retcode = subprocess.getstatusoutput('service {0} status' |
|
|
retcode = subprocess.getstatusoutput('service {0} status' |
|
|
.format(service_name)) |
|
|
.format(service_name)) |
|
@ -97,6 +96,6 @@ class EEService(): |
|
|
else: |
|
|
else: |
|
|
return False |
|
|
return False |
|
|
except OSError as e: |
|
|
except OSError as e: |
|
|
Log.error(self, "Unable to get services status \ {0}{1} [FAIL]" |
|
|
Log.error(self, "Unable to get services status \ {0}{1}{2}" |
|
|
.format(e.errno, e.strerror)) |
|
|
.format(e.errno, e.strerror, "[FAIL]")) |
|
|
return False |
|
|
return False |
|
|