Verified Commit 67bc1308 authored by anarcat's avatar anarcat 💥
Browse files

reboot: allow operator to skip the inter-host delay

That 2 minute pause is kind of annoying when you're wanting to do
reboots more quickly. I keep doing control-c, then editing the
commandline to remove the hosts i've already done...
parent a912657b
Loading
Loading
Loading
Loading
+16 −0
Original line number Original line Diff line number Diff line
@@ -5,6 +5,7 @@ import hashlib
import logging
import logging
import os.path
import os.path
import re
import re
import signal
import sys
import sys


from typing import Optional
from typing import Optional
@@ -281,3 +282,18 @@ def re_include_exclude(


def input_bell(prompt: str = "press enter to continue: ") -> str:
def input_bell(prompt: str = "press enter to continue: ") -> str:
    return input("\a" + prompt)
    return input("\a" + prompt)


def confirm_with_timeout(prompt: str, timeout_secs: int = 120) -> bool:
    def handler(signum, frame):
        raise TimeoutError()

    signal.signal(signal.SIGALRM, handler)
    signal.alarm(timeout_secs)
    try:
        input_bell(prompt)
        signal.alarm(0)
    except TimeoutError:
        return False

    return True
+9 −8
Original line number Original line Diff line number Diff line
@@ -41,6 +41,7 @@ from fabric_tpa.reboot import (
    shutdown_and_wait,
    shutdown_and_wait,
    ShutdownType,
    ShutdownType,
)
)
from fabric_tpa.ui import confirm_with_timeout




# TODO: don't use argparse: use Fabric's "Fab" program wrapper. We
# TODO: don't use argparse: use Fabric's "Fab" program wrapper. We
@@ -156,16 +157,16 @@ def main(args):
        if first:
        if first:
            first = False
            first = False
        else:
        else:
            logging.info(
                "sleeping %d seconds before rebooting %s", args.delay_hosts, hostname
            )
            now = datetime.now(timezone.utc)
            now = datetime.now(timezone.utc)
            logging.info(
            confirm_with_timeout(
                "now is %s, it is safe to interrupt this program until %s",
                "waiting %d seconds before rebooting %s, now is %s waiting until %s or press enter to continue: "
                % (
                    args.delay_hosts,
                    hostname,
                    now,
                    now,
                    now + timedelta(seconds=args.delay_hosts),
                    now + timedelta(seconds=args.delay_hosts),
                )
                )
            time.sleep(args.delay_hosts)
            )
        delay_shutdown = args.delay_shutdown
        delay_shutdown = args.delay_shutdown


        logging.info("rebooting host %s", hostname)
        logging.info("rebooting host %s", hostname)