From f7c3b7333648fc7c62ee5984c4f2db49033fecbe Mon Sep 17 00:00:00 2001 From: madema Date: Wed, 8 May 2013 16:10:22 +0300 Subject: [PATCH 1/2] Added AIX class in the service module to control AIX SRC processes. --- library/system/service | 81 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/library/system/service b/library/system/service index 28e98d1ef06..027545e7c04 100644 --- a/library/system/service +++ b/library/system/service @@ -846,6 +846,87 @@ class SunOSService(Service): return self.execute_command("%s %s %s" % (self.svcadm_cmd, subcmd, self.name)) +# =========================================== +# Subclass: AIX + +class AIX(Service): + """ + This is the AIX Service (SRC) manipulation class - it uses lssrc, startsrc, stopsrc + and refresh for service control. Enabling a service is currently not supported. + Would require to add an entry in the /etc/inittab file (mkitab, chitab and rmitab + commands) + """ + + platform = 'AIX' + distribution = None + + def get_service_tools(self): + self.lssrc_cmd = self.module.get_bin_path('lssrc', True) + + if not self.lssrc_cmd: + self.module.fail_json(msg='unable to find lssrc binary') + + self.startsrc_cmd = self.module.get_bin_path('startsrc', True) + + if not self.startsrc_cmd: + self.module.fail_json(msg='unable to find startsrc binary') + + self.stopsrc_cmd = self.module.get_bin_path('stopsrc', True) + + if not self.stopsrc_cmd: + self.module.fail_json(msg='unable to find stopsrc binary') + + self.refresh_cmd = self.module.get_bin_path('refresh', True) + + if not self.refresh_cmd: + self.module.fail_json(msg='unable to find refresh binary') + + + def get_service_status(self): + rc, stdout, stderr = self.execute_command("%s -s %s" % (self.lssrc_cmd, self.name)) + if rc == 1: + self.running = False + elif rc == 0: + self.running = True + + def get_service_status(self): + status = self.get_aix_src_status() + # Only 'active' is considered properly running. Everything else is off + # or has some sort of problem. + if status == 'active': + self.running = True + else: + self.running = False + + def get_aix_src_status(self): + rc, stdout, stderr = self.execute_command("%s -s %s" % (self.lssrc_cmd, self.name)) + if rc == 1: + if stderr: + self.module.fail_json(msg=stderr) + else: + self.module.fail_json(msg=stdout) + + lines = stdout.rstrip("\n").split("\n") + status = lines[-1].split(" ")[-1] + # status is one of: active, inoperative + return status + + def service_control(self): + if self.action == 'start': + srccmd = self.startsrc_cmd + elif self.action == 'stop': + srccmd = self.stopsrc_cmd + elif self.action == 'reload': + srccmd = self.refresh_cmd + elif self.action == 'restart': + self.execute_command("%s -s %s" % (self.stopsrc_cmd, self.name)) + srccmd = self.startsrc_cmd + + if self.arguments and self.action == 'start': + return self.execute_command("%s -a \"%s\" -s %s" % (srccmd, self.arguments, self.name)) + else: + return self.execute_command("%s -s %s" % (srccmd, self.name)) + # =========================================== # Main control flow From 02e41f3e565ddd03d6af4b784059b58a7727d56e Mon Sep 17 00:00:00 2001 From: madema Date: Fri, 10 May 2013 18:16:23 +0300 Subject: [PATCH 2/2] Update service --- library/system/service | 7 ------- 1 file changed, 7 deletions(-) diff --git a/library/system/service b/library/system/service index 027545e7c04..ca2b661261f 100644 --- a/library/system/service +++ b/library/system/service @@ -882,13 +882,6 @@ class AIX(Service): self.module.fail_json(msg='unable to find refresh binary') - def get_service_status(self): - rc, stdout, stderr = self.execute_command("%s -s %s" % (self.lssrc_cmd, self.name)) - if rc == 1: - self.running = False - elif rc == 0: - self.running = True - def get_service_status(self): status = self.get_aix_src_status() # Only 'active' is considered properly running. Everything else is off