diff options
author | Simo Sorce <ssorce@redhat.com> | 2012-10-22 17:01:58 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2012-11-01 14:24:41 -0400 |
commit | 57132797120bcd3f68380b6b74343af2d83e0657 (patch) | |
tree | 25b9cdf6b8975cb1e2aa175f63d0f47b657e80fa /ipapython/platform | |
parent | 895b2e2b4339f1b9edc2bc995e7548ac118ea5a1 (diff) | |
download | freeipa-57132797120bcd3f68380b6b74343af2d83e0657.tar.gz freeipa-57132797120bcd3f68380b6b74343af2d83e0657.tar.xz freeipa-57132797120bcd3f68380b6b74343af2d83e0657.zip |
Save service name on service startup/shutdown
This is done as a default action of the ancestor class so that no matter what
platform is currently used this code is always the same and the name is the
wellknown service name.
This information will be used by ipactl to stop only and all the services that
have been started by any ipa tool/install script
Diffstat (limited to 'ipapython/platform')
-rw-r--r-- | ipapython/platform/base.py | 42 | ||||
-rw-r--r-- | ipapython/platform/redhat.py | 2 | ||||
-rw-r--r-- | ipapython/platform/systemd.py | 2 |
3 files changed, 46 insertions, 0 deletions
diff --git a/ipapython/platform/base.py b/ipapython/platform/base.py index 2d39d2169..8385e1038 100644 --- a/ipapython/platform/base.py +++ b/ipapython/platform/base.py @@ -17,6 +17,8 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. from ipalib.plugable import MagicDict +import json +import os # Canonical names of services as IPA wants to see them. As we need to have # *some* naming, set them as in Red Hat distributions. Actual implementation @@ -40,6 +42,8 @@ wellknownports = { 'pki-tomcatd': [8080, 8443], # used if the incoming instance name is blank } +SVC_LIST_FILE = "/var/run/ipa/services.list" + class AuthConfig(object): """ AuthConfig class implements system-independent interface to configure @@ -133,9 +137,47 @@ class PlatformService(object): self.service_name = service_name def start(self, instance_name="", capture_output=True, wait=True): + """ + When a service is started record the fact in a special file. + This allows ipactl stop to always stop all services that have + been started via ipa tools + """ + svc_list = [] + try: + f = open(SVC_LIST_FILE, 'r') + svc_list = json.load(f) + except Exception: + # not fatal, may be the first service + pass + + if self.service_name not in svc_list: + svc_list.append(self.service_name) + + f = open(SVC_LIST_FILE, 'w') + json.dump(svc_list, f) + f.flush() + f.close() return def stop(self, instance_name="", capture_output=True): + """ + When a service is stopped remove it from the service list file. + """ + svc_list = [] + try: + f = open(SVC_LIST_FILE, 'r') + svc_list = json.load(f) + except Exception: + # not fatal, may be the first service + pass + + while self.service_name in svc_list: + svc_list.remove(self.service_name) + + f = open(SVC_LIST_FILE, 'w') + json.dump(svc_list, f) + f.flush() + f.close() return def restart(self, instance_name="", capture_output=True, wait=True): diff --git a/ipapython/platform/redhat.py b/ipapython/platform/redhat.py index 3551c2841..1de035568 100644 --- a/ipapython/platform/redhat.py +++ b/ipapython/platform/redhat.py @@ -66,11 +66,13 @@ class RedHatService(base.PlatformService): def stop(self, instance_name="", capture_output=True): ipautil.run(["/sbin/service", self.service_name, "stop", instance_name], capture_output=capture_output) + super(RedHatService, self).stop(instance_name) def start(self, instance_name="", capture_output=True, wait=True): ipautil.run(["/sbin/service", self.service_name, "start", instance_name], capture_output=capture_output) if wait and self.is_running(instance_name): self.__wait_for_open_ports(instance_name) + super(RedHatService, self).start(instance_name) def restart(self, instance_name="", capture_output=True, wait=True): ipautil.run(["/sbin/service", self.service_name, "restart", instance_name], capture_output=capture_output) diff --git a/ipapython/platform/systemd.py b/ipapython/platform/systemd.py index 6c25a79b6..bb6c00929 100644 --- a/ipapython/platform/systemd.py +++ b/ipapython/platform/systemd.py @@ -91,11 +91,13 @@ class SystemdService(base.PlatformService): def stop(self, instance_name="", capture_output=True): ipautil.run(["/bin/systemctl", "stop", self.service_instance(instance_name)], capture_output=capture_output) + super(SystemdService, self).stop(instance_name) def start(self, instance_name="", capture_output=True, wait=True): ipautil.run(["/bin/systemctl", "start", self.service_instance(instance_name)], capture_output=capture_output) if wait and self.is_running(instance_name): self.__wait_for_open_ports(self.service_instance(instance_name)) + super(SystemdService, self).start(instance_name) def restart(self, instance_name="", capture_output=True, wait=True): # Restart command is broken before systemd-36-3.fc16 |