[node-patches] Change in ovirt-node[master]: Update reboot task to run async from installer and install m...

jboggs at redhat.com jboggs at redhat.com
Mon May 6 03:29:49 UTC 2013


Joey Boggs has uploaded a new change for review.

Change subject: Update reboot task to run async from installer and install module
......................................................................

Update reboot task to run async from installer and install module

rhbz#955543

Signed-off-by: Joey Boggs <jboggs at redhat.com>
Change-Id: Ic1b4e048ff56b8c9ebd49a82b3d5546c7c326df8
---
M src/ovirt/node/utils/system.py
M src/ovirtnode/install.py
2 files changed, 78 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/91/14491/1

diff --git a/src/ovirt/node/utils/system.py b/src/ovirt/node/utils/system.py
index c5b9ca6..4b3165a 100644
--- a/src/ovirt/node/utils/system.py
+++ b/src/ovirt/node/utils/system.py
@@ -21,9 +21,10 @@
 from ovirt.node import base, utils
 from ovirt.node.config import defaults
 from ovirt.node.utils import process
-import os.path
+import os
 import rpm
 import system_config_keyboard.keyboard
+import time
 
 """
 A module to access system wide stuff
@@ -34,8 +35,8 @@
 def reboot():
     """Reboot the system
     """
-    process.call("reboot")
-
+    reboot_task = TimedReboot()
+    reboot_task.reboot(10)
 
 def poweroff():
     """Poweroff the system
@@ -62,6 +63,19 @@
     """
     return os.path.exists("/dev/HostVG")
 
+def which(file):
+    ret = None
+    if os.path.abspath(file) and os.path.exists(file):
+        ret = file
+    else:
+        for dir in os.environ["PATH"].split(":"):
+            f = os.path.join(dir, file)
+            if os.path.exists(f) and os.access(f, os.X_OK):
+                ret = f
+                break
+    if ret is None:
+        raise RuntimeError("Cannot find command '%s'" % file)
+    return ret
 
 class SystemRelease(base.Base):
     """Informations about the OS based on /etc/system-release-cpe
@@ -245,3 +259,61 @@
     def is_upgrade(self):
         #ovirtfunctions.is_upgrade()
         return self._model.retrieve()["upgrade"] is True
+
+
+class TimedReboot(base.Base):
+    def simpleDaemon(self, main, args=(), kwargs={}):
+        # Default maximum for the number of available file descriptors.
+        MAXFD = 1024
+
+        import resource  # Resource usage information.
+        maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
+        if (maxfd == resource.RLIM_INFINITY):
+            maxfd = MAXFD
+
+        pid = os.fork()
+        if pid == 0:
+            try:
+                os.chdir('/')
+                os.setsid()
+                for fd in range(0, maxfd):
+                    try:
+                        os.close(fd)
+                    except OSError:
+                        # ERROR, fd wasn't open to begin with (ignored)
+                        pass
+
+                os.open(os.devnull, os.O_RDWR)  # standard input (0)
+                os.dup2(0, 1)  # standard output (1)
+                os.dup2(0, 2)  # standard error (2)
+
+                if os.fork() != 0:
+                    os._exit(0)
+
+                try:
+                    main(*args, **kwargs)
+                except:
+                    import traceback
+                    traceback.print_exc()
+            finally:
+                os._exit(1)
+
+        pid, status = os.waitpid(pid, 0)
+
+        if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0:
+            raise RuntimeError('Daemon not exited properly')
+
+    def delayedReboot(self, reboot, sleepTime):
+        time.sleep(sleepTime)
+        os.execl(reboot, reboot)
+
+    def reboot(self, delay):
+        self.logger.info("Scheduling Reboot")
+        self.simpleDaemon(
+            self.delayedReboot,
+            (
+                which("reboot"),
+                delay,
+            )
+        )
+        self.logger.info("Reboot Scheduled")
diff --git a/src/ovirtnode/install.py b/src/ovirtnode/install.py
index d78ba1b..9bd2602 100755
--- a/src/ovirtnode/install.py
+++ b/src/ovirtnode/install.py
@@ -18,6 +18,7 @@
 # also available at http://www.gnu.org/copyleft/gpl.html.
 
 import ovirtnode.ovirtfunctions as _functions
+import ovirt.node.utils.system as _system
 import ovirtnode.iscsi as _iscsi
 import shutil
 import traceback
@@ -581,13 +582,8 @@
             logger.info("Installation of %s Completed" % \
                                                       _functions.PRODUCT_SHORT)
             if reboot is not None and reboot == "Y":
-                f = open('/var/spool/cron/root', 'w')
-                f.write('* * * * * sleep 10 && /sbin/reboot\n')
-                f.close()
-                #ensure crond is started
-                _functions.subprocess_closefds("crond", shell=True,
-                                    stdout=subprocess.PIPE,
-                                    stderr=subprocess.STDOUT)
+                reboot_task = _system.TimedReboot()
+                reboot_task.reboot(10)
             return True
         else:
             return False


--
To view, visit http://gerrit.ovirt.org/14491
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic1b4e048ff56b8c9ebd49a82b3d5546c7c326df8
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Joey Boggs <jboggs at redhat.com>



More information about the node-patches mailing list