From 39b7e7e60efb70066ddcc23fd8ae1c4f3dc2f088 Mon Sep 17 00:00:00 2001 From: William Brown Date: Fri, 30 Oct 2015 11:33:01 +1000 Subject: [PATCH] Ticket 47840 - fix lib389 to use sbin scripts https://fedorahosted.org/389/ticket/47840 Bug Description: Now that https://fedorahosted.org/389/ticket/528 is fixed, the next step is to allow building the server with the instance specific scripts disabled. Fix Description: As we do not install instance scripts by default we cannot rely on their existance. This patch fixes the serverCmd function in lib389 to use the sbin scripts, as well as providing two clitools for start/stop that can be used to prove this functionality works. Example: python lib389/clitools/ds_start.py python lib389/clitools/ds_stop.py Author: wibrown Review by: nhosoi --- clitools/ds_start.py | 26 ++++++++++++++++++++++++++ clitools/ds_stop.py | 26 ++++++++++++++++++++++++++ lib389/tools.py | 14 +++++++++----- 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 clitools/ds_start.py create mode 100644 clitools/ds_stop.py diff --git a/clitools/ds_start.py b/clitools/ds_start.py new file mode 100644 index 0000000..b572f13 --- /dev/null +++ b/clitools/ds_start.py @@ -0,0 +1,26 @@ +#!/usr/bin/python + +#from clitools import clitools_parser, get_instance_dict, get_rootdn_pass +from clitools import CliTool, clitools_parser +#from lib389 import DirSrv +from lib389._constants import * +from lib389.tools import DirSrvTools +import ldap + +class StartTool(CliTool): + def start(self): + try: + self.populate_instance_dict(self.args.instance) + self.ds.allocate(self.inst) + + DirSrvTools.serverCmd(self.ds, "start", True) + finally: + pass + #self.disconnect() + +if __name__ == '__main__': + # Do some arg parse stuff + ## You can always add a child parser here too ... + args = clitools_parser.parse_args() + tool = StartTool(args) + tool.start() diff --git a/clitools/ds_stop.py b/clitools/ds_stop.py new file mode 100644 index 0000000..fdbed35 --- /dev/null +++ b/clitools/ds_stop.py @@ -0,0 +1,26 @@ +#!/usr/bin/python + +#from clitools import clitools_parser, get_instance_dict, get_rootdn_pass +from clitools import CliTool, clitools_parser +#from lib389 import DirSrv +from lib389._constants import * +from lib389.tools import DirSrvTools +import ldap + +class StartTool(CliTool): + def start(self): + try: + self.populate_instance_dict(self.args.instance) + self.ds.allocate(self.inst) + + DirSrvTools.serverCmd(self.ds, "stop", True) + finally: + pass + #self.disconnect() + +if __name__ == '__main__': + # Do some arg parse stuff + ## You can always add a child parser here too ... + args = clitools_parser.parse_args() + tool = StartTool(args) + tool.start() diff --git a/lib389/tools.py b/lib389/tools.py index af72a61..468b01e 100644 --- a/lib389/tools.py +++ b/lib389/tools.py @@ -172,7 +172,8 @@ class DirSrvTools(object): assert len(props) == 1 self.sroot = props[0][CONF_SERVER_DIR] - instanceDir = os.path.join(self.sroot, "slapd-" + self.inst) + #instanceDir = os.path.join(self.sroot, "slapd-" + self.inst) + sbinDir = os.path.join(self.prefix + '/sbin') if hasattr(self, 'errlog'): errLog = self.errlog @@ -182,10 +183,13 @@ class DirSrvTools(object): started = True lastLine = "" cmd = cmd.lower() - fullCmd = instanceDir + "/" + cmd + "-slapd" + #fullCmd = instanceDir + "/" + cmd + "-slapd" + fullCmd = None if cmd == 'start': + fullCmd = os.path.join(sbinDir, 'start-dirsrv') cmdPat = 'slapd started.' else: + fullCmd = os.path.join(sbinDir, 'stop-dirsrv') cmdPat = 'slapd stopped.' if "USE_GDB" in os.environ or "USE_VALGRIND" in os.environ: @@ -205,7 +209,7 @@ class DirSrvTools(object): pos = logfp.tell() # get current position logfp.seek(pos, os.SEEK_SET) # reset the EOF flag - log.warn("Running command: %r" % fullCmd) + log.warn("Running command: %r %s" % (fullCmd, self.serverid )) rc = os.system(fullCmd) while not done and int(time.time()) < timeout: line = logfp.readline() @@ -219,12 +223,12 @@ class DirSrvTools(object): done = True elif line.find("Initialization Failed") >= 0: # sometimes the server fails to start - try again - rc = os.system(fullCmd) + rc = os.system("%s %s" % (fullCmd, self.serverid)) pos = logfp.tell() break elif line.find("exiting.") >= 0: # possible transient condition - try again - rc = os.system(fullCmd) + rc = os.system("%s %s" % (fullCmd, self.serverid)) pos = logfp.tell() break pos = logfp.tell() -- 2.4.3