Yaniv Bronhaim has uploaded a new change for review. Change subject: [WIP] creating supervdsm service ......................................................................
[WIP] creating supervdsm service Also modifying supervdsm.py to work with service, removing kill and start management. Only communication to the service is required. Change-Id: I290a584f38129406cd390fdd1d3d1aad9f829a60 Signed-off-by: Yaniv Bronhaim <[email protected]> --- M vdsm.spec.in M vdsm/Makefile.am M vdsm/clientIF.py M vdsm/supervdsm.py M vdsm/supervdsmServer.py A vdsm/supervdsmd.init.in A vdsm/supervdsmd.service M vdsm/vdsmd.service 8 files changed, 141 insertions(+), 112 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/51/11051/1 diff --git a/vdsm.spec.in b/vdsm.spec.in index 2fc9980..157be43 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -441,6 +441,7 @@ %if 0%{?rhel} # Install the SysV init scripts install -Dm 0755 vdsm/vdsmd.init %{buildroot}%{_initrddir}/vdsmd +install -Dm 0755 vdsm/supervdsmd.init %{buildroot}%{_initrddir}/supervdsmd install -Dm 0755 vdsm_reg/vdsm-reg.init %{buildroot}%{_initrddir}/vdsm-reg # This is not commonplace, but we want /var/log/core to be a world-writable @@ -453,7 +454,9 @@ # Install the systemd scripts install -Dm 0755 vdsm/vdsmd.init %{buildroot}/lib/systemd/systemd-vdsmd +install -Dm 0755 vdsm/supervdsmd.init %{buildroot}/lib/systemd/systemd-supervdsmd install -Dm 0644 vdsm/vdsmd.service %{buildroot}%{_unitdir}/vdsmd.service +install -Dm 0644 vdsm/supervdsmd.service %{buildroot}%{_unitdir}/supervdsmd.service install -Dm 0755 vdsm_reg/vdsm-reg.init \ %{buildroot}/lib/systemd/systemd-vdsm-reg install -Dm 0644 vdsm_reg/vdsm-reg.service \ @@ -507,6 +510,7 @@ %else if [ "$1" -eq 1 ] ; then /bin/systemctl enable vdsmd.service >/dev/null 2>&1 || : + /bin/systemctl enable supervdsmd.service >/dev/null 2>&1 || : /bin/systemctl daemon-reload >/dev/null 2>&1 || : fi exit 0 @@ -544,6 +548,8 @@ if [ "$1" -eq 0 ]; then /bin/systemctl --no-reload disable vdsmd.service > /dev/null 2>&1 || : /bin/systemctl stop vdsmd.service > /dev/null 2>&1 || : + /bin/systemctl --no-reload disable supervdsmd.service > /dev/null 2>&1 || : + /bin/systemctl stop supervdsmd.service > /dev/null 2>&1 || : fi exit 0 %endif @@ -557,6 +563,7 @@ %else if [ "$1" -ge 1 ] ; then /bin/systemctl try-restart vdsmd.service >/dev/null 2>&1 || : + /bin/systemctl try-restart supervdsmd.service >/dev/null 2>&1 || : fi exit 0 %endif @@ -606,9 +613,12 @@ %doc COPYING README vdsm/vdsm.conf.sample vdsm_api/vdsm-api.html %if 0%{?rhel} %{_initrddir}/vdsmd +%{_initrddir}/supervdsmd %else /lib/systemd/systemd-vdsmd +/lib/systemd/systemd-supervdsmd %{_unitdir}/vdsmd.service +%{_unitdir}/supervdsmd.service %endif %dir %attr(-, %{vdsm_user}, %{vdsm_group}) @vdsmrepo@ %ghost %dir %attr(-, %{vdsm_user}, %{vdsm_group}) @vdsmrepo@/hsm-tasks @@ -632,7 +642,7 @@ %{_datadir}/%{vdsm_name}/parted_utils.py* %{_datadir}/%{vdsm_name}/mkimage.py* %{_datadir}/%{vdsm_name}/supervdsm.py* -%{_datadir}/%{vdsm_name}/supervdsmServer.py* +%attr (755,root,root) %{_datadir}/%{vdsm_name}/supervdsmServer.py* %{_datadir}/%{vdsm_name}/vmChannels.py* %{_datadir}/%{vdsm_name}/tc.py* %{_datadir}/%{vdsm_name}/vdsm diff --git a/vdsm/Makefile.am b/vdsm/Makefile.am index 88b3287..2bda2f2 100644 --- a/vdsm/Makefile.am +++ b/vdsm/Makefile.am @@ -91,7 +91,8 @@ vdsm-logrotate.conf \ vdsm.conf.sample \ vdsm.rwtab \ - vdsmd.init + vdsmd.init \ + supervdsmd.init dist_vdsm_SCRIPTS = \ addNetwork \ @@ -130,7 +131,9 @@ sudoers.vdsm.in \ vdsmd.8.in \ vdsmd.init.in \ + supervdsmd.init.in \ vdsmd.service \ + supervdsmd.service \ vdsm-gencerts.sh.in \ vdsm-libvirt-access.pkla \ vdsm-libvirt-access.rules \ diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py index 0aadbf4..207defe 100644 --- a/vdsm/clientIF.py +++ b/vdsm/clientIF.py @@ -492,6 +492,8 @@ continue if f == 'svdsm.sock': continue + if f == 'supervdsm_respawn.pid': + continue else: continue self.log.debug("removing old file " + f) diff --git a/vdsm/supervdsm.py b/vdsm/supervdsm.py index 6a38076..6b445d3 100644 --- a/vdsm/supervdsm.py +++ b/vdsm/supervdsm.py @@ -24,11 +24,6 @@ from multiprocessing.managers import BaseManager import logging import threading -import uuid -from time import sleep -from errno import ENOENT, ESRCH - -import storage.misc as misc from vdsm import constants, utils _g_singletonSupervdsmInstance = None @@ -80,10 +75,9 @@ try: return callMethod() # handling internal exception that we raise to identify supervdsm - # validation. only this exception can cause kill! + # validation. except AuthenticationError: with self._supervdsmProxy.proxyLock: - self._supervdsmProxy.kill() self._supervdsmProxy.launch() return callMethod() @@ -96,86 +90,21 @@ def __init__(self): self.proxyLock = threading.Lock() - self._firstLaunch = True + # TODO: read from file + self._authkey = '1234' # Declaration of public variables that keep files' names that svdsm # uses. We need to be able to change these variables so that running # tests doesn't disturb and already running VDSM on the host. - self.setIPCPaths(PIDFILE, TIMESTAMP, ADDRESS) - - def setIPCPaths(self, pidfile, timestamp, address): - self.pidfile = pidfile - self.timestamp = timestamp - self.address = address + self.address = ADDRESS def open(self, *args, **kwargs): return self._manager.open(*args, **kwargs) - def _cleanOldFiles(self): - self._log.debug("Cleanning svdsm old files: %s, %s, %s", - self.pidfile, self.timestamp, self.address) - for f in (self.pidfile, self.timestamp, self.address): - utils.rmFile(f) - - def _start(self): - self._authkey = str(uuid.uuid4()) - self._log.debug("Launching Super Vdsm") - - # we pass to svdsm filenames and uid. Svdsm will use those filenames - # to create its internal files and give to the passed uid the - # permissions to read those files. - superVdsmCmd = [constants.EXT_PYTHON, SUPERVDSM, - self._authkey, str(os.getpid()), - self.pidfile, self.timestamp, self.address, - str(os.getuid())] - - misc.execCmd(superVdsmCmd, sync=False, sudo=True) - sleep(2) - - def kill(self): - try: - with open(self.pidfile, "r") as f: - pid = int(f.read().strip()) - misc.execCmd([constants.EXT_KILL, "-9", str(pid)], sudo=True) - except Exception: - self._log.error("Could not kill old Super Vdsm %s", - exc_info=True) - - self._cleanOldFiles() - self._authkey = None - self._manager = None - self._svdsm = None - self._firstLaunch = True - def isRunning(self): - if self._firstLaunch or self._svdsm is None: - return False - try: - with open(self.pidfile, "r") as f: - spid = f.read().strip() - with open(self.timestamp, "r") as f: - createdTime = f.read().strip() - except IOError as e: - # pid file and timestamp file must be exist after first launch, - # otherwise excpetion will be raised to svdsm caller - if e.errno == ENOENT and self._firstLaunch: - return False - else: - raise - - try: - pTime = str(misc.getProcCtime(spid)) - except OSError as e: - if e.errno == ESRCH: - # Means pid is not exist, svdsm was killed - return False - else: - raise - - if pTime == createdTime: - return True - else: + return self._svdsm.ping() + except: return False def _connect(self): @@ -192,8 +121,6 @@ self._svdsm = self._manager.instance() def launch(self): - self._firstLaunch = False - self._start() utils.retry(self._connect, Exception, timeout=60) def __getattr__(self, name): diff --git a/vdsm/supervdsmServer.py b/vdsm/supervdsmServer.py index b55a5e9..f4c7912 100755 --- a/vdsm/supervdsmServer.py +++ b/vdsm/supervdsmServer.py @@ -1,3 +1,5 @@ +#!/usr/bin/python +# # Copyright 2011 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify @@ -26,7 +28,6 @@ import errno import threading import re -from time import sleep import signal from multiprocessing import Pipe, Process from gluster import cli as gcli @@ -332,17 +333,6 @@ return self.__udevVersion() > self.UDEV_WITH_RELOAD_VERSION -def __pokeParent(parentPid, address, log): - try: - while True: - os.kill(parentPid, 0) - sleep(2) - except Exception: - utils.rmFile(address) - log.debug("Killing SuperVdsm Process") - os.kill(os.getpid(), signal.SIGTERM) - - def main(): def bind(func): def wrapper(_SuperVdsm, *args, **kwargs): @@ -372,28 +362,13 @@ sys.exit(errno.EPERM) log.debug("Parsing cmd args") - authkey, parentPid, pidfile, timestamp, address, uid = sys.argv[1:] - - log.debug("Creating PID and TIMESTAMP files: %s, %s", - pidfile, timestamp) - spid = os.getpid() - with open(pidfile, "w") as f: - f.write(str(spid) + "\n") - with open(timestamp, "w") as f: - f.write(str(misc.getProcCtime(spid) + "\n")) + authkey, address, uid = sys.argv[1:] log.debug("Cleaning old socket %s", address) if os.path.exists(address): os.unlink(address) zombieReaper.registerSignalHandler() - - log.debug("Setting up keep alive thread") - - monThread = threading.Thread(target=__pokeParent, - args=[int(parentPid), address, log]) - monThread.setDaemon(True) - monThread.start() try: log.debug("Creating remote object manager") @@ -405,8 +380,7 @@ servThread.setDaemon(True) servThread.start() - for f in (address, timestamp, pidfile): - chown(f, int(uid), METADATA_GROUP) + chown(address, int(uid), METADATA_GROUP) log.debug("Started serving super vdsm object") diff --git a/vdsm/supervdsmd.init.in b/vdsm/supervdsmd.init.in new file mode 100755 index 0000000..76e1f28 --- /dev/null +++ b/vdsm/supervdsmd.init.in @@ -0,0 +1,102 @@ +#! /bin/sh +# +# Copyright 2006-2010 Red Hat, Inc. and/or its affiliates. +# +# Licensed to you under the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. See the files README and +# LICENSE_GPL_v2 which accompany this distribution. +# + +# chkconfig: 2345 99 00 +# +### BEGIN INIT INFO +# Provides: supervdsmd +# Required-Start: $syslog $network $vdsmd +# Should-Start: $time $vdsmd +# Required-Stop: $syslog $vdsmd +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: init script for the Super VDS management server +# Short-Description: init script for the Super VDS management server +### END INIT INFO + +SUPERVDSM_BIN=@VDSMDIR@/supervdsmServer.py +PIDFILE=@VDSMRUNDIR@/supervdsmd.pid +RESPAWNPIDFILE=@VDSMRUNDIR@/supervdsm_respawn.pid +# TODO: shouldn't be hardcoded, need to move the constant to confiure.ac +SOCKFILE='/var/run/vdsm/svdsm.sock' +VDSM_USER=`id -u vdsm` +# TODO: should be read from file +AUTH_KEY='1234' + +log_failure_msg() { echo -n "$@"; failure "$@"; echo; } +log_success_msg() { echo -n "$@"; success "$@"; echo; } + +start(){ + LC_ALL=C @VDSMDIR@/respawn --minlifetime 10 --daemon --masterpid $RESPAWNPIDFILE $SUPERVDSM_BIN $AUTH_KEY $SOCKFILE $VDSM_USER + RETVAL=$? + [ "$RETVAL" -eq 0 ] && log_success_msg $"$prog start" || log_failure_msg $"$prog start" +} + +stop(){ + echo $"Shutting down supervdsm daemon: " + if killproc -p $RESPAWNPIDFILE; then + log_success_msg $"$prog watchdog stop" + fi + if ! pidofproc -p $PIDFILE >/dev/null; then + log_failure_msg "$prog: not running" + RETVAL=0 + else + killproc -p $PIDFILE -d 2 + RETVAL=$? + [ "$RETVAL" -eq 0 ] && log_success_msg $"$prog stop" || log_failure_msg $"$prog stop" + [ "$RETVAL" -eq 0 ] && rm -f /var/lock/subsys/vdsmd + fi + return $RETVAL +} + +case "$1" in + start) + start + RETVAL=$? + ;; + stop) + stop + RETVAL=$? + ;; + status) + pidofproc -p $PIDFILE $SUPERVDSM_BIN >/dev/null + RETVAL=$? + if [ "$RETVAL" -eq 0 ]; then + echo "Super VDSM daemon server is running" + else + echo -n "Super VDSM daemon is not running" + if pidofproc -p $RESPAWNPIDFILE >/dev/null; then + echo ", but its watchdog is" + else + echo + fi + fi + ;; + condrestart) + pidofproc -p $PIDFILE $VDSM_BIN >/dev/null + RETVAL=$? + if [ "$RETVAL" -eq 0 ]; then + $0 stop && $0 start; + RETVAL=$?; + fi; + ;; + try-restart|restart|force-reload) + $0 stop && $0 start + RETVAL=$? + ;; + *) + echo "Usage: $0 {start|stop|status|restart|force-reload|try-restart}" + RETVAL=2 +esac + +exit $RETVAL + + + diff --git a/vdsm/supervdsmd.service b/vdsm/supervdsmd.service new file mode 100644 index 0000000..1bd7f50 --- /dev/null +++ b/vdsm/supervdsmd.service @@ -0,0 +1,11 @@ +[Unit] +Description=Super VDSM + +[Service] +Type=forking +EnvironmentFile=-/etc/sysconfig/supervdsm +ExecStart=/lib/systemd/systemd-supervdsmd start +ExecStop=/lib/systemd/systemd-supervdsmd stop + +[Install] +WantedBy=multi-user.target diff --git a/vdsm/vdsmd.service b/vdsm/vdsmd.service index 6a650f4..9ac28a2 100644 --- a/vdsm/vdsmd.service +++ b/vdsm/vdsmd.service @@ -1,6 +1,6 @@ [Unit] Description=Virtual Desktop Server Manager -Requires=multipathd.service libvirtd.service ntpd.service +Requires=multipathd.service libvirtd.service ntpd.service supervdsmd.service Conflicts=libvirt-guests.service [Service] -- To view, visit http://gerrit.ovirt.org/11051 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I290a584f38129406cd390fdd1d3d1aad9f829a60 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Yaniv Bronhaim <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
