On Wed, May 27, 2009 at 10:42:34AM +0100, Guido Trotter wrote:
> On Wed, May 27, 2009 at 10:40 AM, Iustin Pop <[email protected]> wrote:
> > On Wed, May 27, 2009 at 10:14:53AM +0100, Guido Trotter wrote:
> >> On Tue, May 26, 2009 at 6:45 PM, Iustin Pop <[email protected]> wrote:
> >> > +
> >> > + �...@classmethod
> >> > + def LinuxPowercycle(cls):
> >> > + """Linux-specific powercycle method.
> >> > +
> >> > + """
> >> > + fd = os.open("/proc/sysrq-trigger", os.O_WRONLY)
> >>
> >> Should we check that it exists before actually opening it?
> >> Or catch an error in the os.open call. We can at least try to log the
> >> error.
> >
> > So I expect here that opening will fail, and the normal handler will log it.
> >
> > But good point, we can make it more explicit. I'd propose:
> > - try to open
> > - if fail:
> > - run “telinit 6”? or shutdown -r?
> >
>
> sure, this works! (no particular preference from me between those two...)
Even though it's deprecated, "shutdown -r -n now" seems the fastest way
to reboot. Or, alternatively, a small C wrapper over the ‘reboot()’
function could be used.
Interdiff:
diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py
index 1358e54..e97dc92 100644
--- a/lib/hypervisor/hv_base.py
+++ b/lib/hypervisor/hv_base.py
@@ -364,8 +364,14 @@ class BaseHypervisor(object):
"""Linux-specific powercycle method.
"""
- fd = os.open("/proc/sysrq-trigger", os.O_WRONLY)
try:
- os.write(fd, "b")
- finally:
- fd.close()
+ fd = os.open("/proc/sysrq-trigger", os.O_WRONLY)
+ try:
+ os.write(fd, "b")
+ finally:
+ fd.close()
+ except OSError:
+ logging.exception("Can't open the sysrq-trigger file")
+ result = utils.RunCmd(["shutdown", "-r", "-n", "now"])
+ if not result:
+ logging.error("Can't run shutdown: %s", result.output)
--
iustin