Yaniv Bronhaim has uploaded a new change for review.
Change subject: Changing the order of the services management alternatives ......................................................................
Changing the order of the services management alternatives
Prefer initctl, then systemctl
Change-Id: I678cee34d02ebbdcccd49f4c95cca9aa90f6fab3 Signed-off-by: Yaniv Bronhaim ybronhei@redhat.com --- M lib/vdsm/tool/service.py 1 file changed, 66 insertions(+), 64 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/67/22867/1
diff --git a/lib/vdsm/tool/service.py b/lib/vdsm/tool/service.py index ee6a9cd..505a385 100644 --- a/lib/vdsm/tool/service.py +++ b/lib/vdsm/tool/service.py @@ -98,73 +98,10 @@ pass
-try: - _SYSTEMCTL.cmd -except OSError: - pass -else: - def _systemctlNative(systemctlFun): - @functools.wraps(systemctlFun) - def wrapper(srvName): - cmd = [_SYSTEMCTL.cmd, "--no-pager", "list-unit-files"] - rc, out, err = execCmd(cmd, raw=False) - if rc != 0: - raise ServiceOperationError( - "Error listing unit files", '\n'.join(out), '\n'.join(err)) - fullName = srvName + ".service" - for line in out: - if fullName == line.split(" ", 1)[0]: - return systemctlFun(fullName) - raise ServiceNotExistError("%s is not native systemctl service" % - srvName) - return wrapper - - @_systemctlNative - def _systemctlStart(srvName): - cmd = [_SYSTEMCTL.cmd, "start", srvName] - return execCmd(cmd) - - @_systemctlNative - def _systemctlStop(srvName): - cmd = [_SYSTEMCTL.cmd, "stop", srvName] - return execCmd(cmd) - - @_systemctlNative - def _systemctlStatus(srvName): - cmd = [_SYSTEMCTL.cmd, "status", srvName] - return execCmd(cmd) - - @_systemctlNative - def _systemctlRestart(srvName): - cmd = [_SYSTEMCTL.cmd, "restart", srvName] - return execCmd(cmd) - - @_systemctlNative - def _systemctlReload(srvName): - cmd = [_SYSTEMCTL.cmd, "reload", srvName] - return execCmd(cmd) - - @_systemctlNative - def _systemctlDisable(srvName): - cmd = [_SYSTEMCTL.cmd, "disable", srvName] - return execCmd(cmd) - - @_systemctlNative - def _systemctlIsManaged(srvName): - return (0, '', '') - - _srvStartAlts.append(_systemctlStart) - _srvStopAlts.append(_systemctlStop) - _srvStatusAlts.append(_systemctlStatus) - _srvRestartAlts.append(_systemctlRestart) - _srvReloadAlts.append(_systemctlReload) - _srvDisableAlts.append(_systemctlDisable) - _srvIsManagedAlts.append(_systemctlIsManaged) - - def _isStopped(message): stopRegex = r"\bstopped\b|\bstop\b|\bwaiting\b|\bnot running\b" return bool(re.search(stopRegex, message, re.MULTILINE)) +
try: _INITCTL.cmd @@ -258,6 +195,71 @@ raise ServiceNotExistError("%s is not a SysV service" % srvName) return wrapper
+ +try: + _SYSTEMCTL.cmd +except OSError: + pass +else: + def _systemctlNative(systemctlFun): + @functools.wraps(systemctlFun) + def wrapper(srvName): + cmd = [_SYSTEMCTL.cmd, "--no-pager", "list-unit-files"] + rc, out, err = execCmd(cmd, raw=False) + if rc != 0: + raise ServiceOperationError( + "Error listing unit files", '\n'.join(out), '\n'.join(err)) + fullName = srvName + ".service" + for line in out: + if fullName == line.split(" ", 1)[0]: + return systemctlFun(fullName) + raise ServiceNotExistError("%s is not native systemctl service" % + srvName) + return wrapper + + @_systemctlNative + def _systemctlStart(srvName): + cmd = [_SYSTEMCTL.cmd, "start", srvName] + return execCmd(cmd) + + @_systemctlNative + def _systemctlStop(srvName): + cmd = [_SYSTEMCTL.cmd, "stop", srvName] + return execCmd(cmd) + + @_systemctlNative + def _systemctlStatus(srvName): + cmd = [_SYSTEMCTL.cmd, "status", srvName] + return execCmd(cmd) + + @_systemctlNative + def _systemctlRestart(srvName): + cmd = [_SYSTEMCTL.cmd, "restart", srvName] + return execCmd(cmd) + + @_systemctlNative + def _systemctlReload(srvName): + cmd = [_SYSTEMCTL.cmd, "reload", srvName] + return execCmd(cmd) + + @_systemctlNative + def _systemctlDisable(srvName): + cmd = [_SYSTEMCTL.cmd, "disable", srvName] + return execCmd(cmd) + + @_systemctlNative + def _systemctlIsManaged(srvName): + return (0, '', '') + + _srvStartAlts.append(_systemctlStart) + _srvStopAlts.append(_systemctlStop) + _srvStatusAlts.append(_systemctlStatus) + _srvRestartAlts.append(_systemctlRestart) + _srvReloadAlts.append(_systemctlReload) + _srvDisableAlts.append(_systemctlDisable) + _srvIsManagedAlts.append(_systemctlIsManaged) + + try: _SERVICE.cmd except OSError:
Yaniv Bronhaim has posted comments on this change.
Change subject: Changing the order of the services management alternatives ......................................................................
Patch Set 1: Verified+1
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Changing the order of the services management alternatives ......................................................................
Patch Set 1:
Build Successful
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/6473/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit_el/5580/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_pep8_gerrit/6386/ : SUCCESS
Zhou Zheng Sheng has posted comments on this change.
Change subject: Changing the order of the services management alternatives ......................................................................
Patch Set 1:
Could you explain why it should prefer initctl then systemctl? It's not obvious to me. Maybe you can add some reasons in the commit message.
Dan Kenigsberg has posted comments on this change.
Change subject: Changing the order of the services management alternatives ......................................................................
Patch Set 1: Code-Review-1
Zhou is right - please explain your motivations in the commit message.
Yaniv Bronhaim has posted comments on this change.
Change subject: Changing the order of the services management alternatives ......................................................................
Patch Set 1:
It's a bit hard for me to explain.. maybe you can assist. The reason for that was the way we stop and start libvirtd, which controlled by initctl thanks to our hack in libvirtd_sysv2upstart. The service.py tool tries all alternatives, using SysV verbs will work and will ruin our upstart usage. This case mainly relevant over RHEL 6 which contains both inits to use. With the patch I'm avoiding the problem of mixing up the usage of the services management and prefer the initctl one which we use to start libvirt.
Without it, we check libvirtd status with systemctl (which works..) and get that the service is stopped which is wrong.
Any idea for another option to handle this ? or another option to explain it ?
Nir Soffer has posted comments on this change.
Change subject: Changing the order of the services management alternatives ......................................................................
Patch Set 1:
Can put a table somewhere - maybe in the wiki, that show which service mechanism is used for each platform and service and why?
I don't understand why need to "prefer" something instead of use configuration. For example, if libvirt is configured to use initctl on some platforms, we use initctl for starting, stopping and getting status.
Yaniv Bronhaim has posted comments on this change.
Change subject: Changing the order of the services management alternatives ......................................................................
Patch Set 1:
sure, but service.py doesn't work that way. it tries all alternatives in specific order. both works for retrieving the service status, but it depends on what you used at first to start the service.
its not wrong to start libvirtd with sysV, but vdsmd already starts libvirtrd with initctl, and now when using the service_status we should use initctl for that.
its either changing the alternatives order or have a specific solution for libvirtd, as far as I see it (as you describe as a table with one column for libvirtd)
Zhou Zheng Sheng has posted comments on this change.
Change subject: Changing the order of the services management alternatives ......................................................................
Patch Set 1:
Hi, I think on RHEL6, SysV init and Upstart co-exists. I don't see why systemctl related code are moved, they are related to SystemD. In service.py SysV init already comes after Upstart.
Yaniv Bronhaim has posted comments on this change.
Change subject: Changing the order of the services management alternatives ......................................................................
Patch Set 1:
You are right and I missed that..
Look at my first comment on https://bugzilla.redhat.com/show_bug.cgi?id=1047514 , it explains my miss understanding
Yaniv Bronhaim has abandoned this change.
Change subject: Changing the order of the services management alternatives ......................................................................
Abandoned
not needed
vdsm-patches@lists.fedorahosted.org