Alon Bar-Lev has uploaded a new change for review.
Change subject: bootstrap: perform reboot asynchronously
......................................................................
bootstrap: perform reboot asynchronously
The use of /sbin/reboot may cause reboot to be performed at the middle
of script execution.
Reboot should be delayed in background so that script will have a fair
chance to terminate properly.
Change-Id: I0abb02ae4d5033a8b9f2d468da86fcdc53e2e1c2
Signed-off-by: Alon Bar-Lev <alonbl(a)redhat.com>
---
M vdsm_reg/deployUtil.py.in
1 file changed, 39 insertions(+), 5 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/83/7783/1
diff --git a/vdsm_reg/deployUtil.py.in b/vdsm_reg/deployUtil.py.in
index ebc7d36..b72cb44 100644
--- a/vdsm_reg/deployUtil.py.in
+++ b/vdsm_reg/deployUtil.py.in
@@ -166,13 +166,47 @@
def reboot():
"""
- This function reboots the machine.
+ This function reboots the machine async
"""
- fReturn = True
+ fReturn = False
- out, err, ret = _logExec([EX_REBOOT])
- if ret:
- fReturn = False
+ # 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
+
+ try:
+ pid = os.fork()
+ if pid == 0:
+ try:
+ 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)
+
+ time.sleep(10)
+ os.execl(EX_REBOOT, EX_REBOOT)
+ finally:
+ os._exit(1)
+
+ pid, status = os.waitpid(pid, 0)
+
+ if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0:
+ fReturn = True
+ except OSError:
+ pass
return fReturn
--
To view, visit
http://gerrit.ovirt.org/7783
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0abb02ae4d5033a8b9f2d468da86fcdc53e2e1c2
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <alonbl(a)redhat.com>