add an immediate parameter to request immediate reboot

This commit is contained in:
Michael Hudson-Doyle 2021-08-19 14:12:32 +12:00
parent fc39247073
commit a2675b6ca6
2 changed files with 20 additions and 7 deletions

View File

@ -236,7 +236,7 @@ class API:
def POST(tz: str): ... def POST(tz: str): ...
class shutdown: class shutdown:
def POST(): ... def POST(immediate: bool = False): ...
class LinkAction(enum.Enum): class LinkAction(enum.Enum):

View File

@ -35,25 +35,37 @@ class ShutdownController(SubiquityController):
def __init__(self, app): def __init__(self, app):
super().__init__(app) super().__init__(app)
# user_shutdown_event is set when the user requests the shutdown.
# server_reboot_event is set when the server is ready for shutdown
# shuttingdown_event is set when the shutdown has begun (so don't
# depend on anything actually happening after it is set, it's all a bag
# of races from that point!)
self.user_shutdown_event = asyncio.Event() self.user_shutdown_event = asyncio.Event()
self.server_reboot_event = asyncio.Event()
self.shuttingdown_event = asyncio.Event() self.shuttingdown_event = asyncio.Event()
async def POST(self): async def POST(self, immediate: bool = False):
self.app.controllers.Install.stop_uu() self.app.controllers.Install.stop_uu()
self.user_shutdown_event.set() self.user_shutdown_event.set()
if immediate:
self.server_reboot_event.set()
await self.shuttingdown_event.wait() await self.shuttingdown_event.wait()
def interactive(self): def interactive(self):
return self.app.interactive return self.app.interactive
def start(self): def start(self):
self.app.aio_loop.create_task(self._wait_install())
self.app.aio_loop.create_task(self._run()) self.app.aio_loop.create_task(self._run())
async def _run(self): async def _wait_install(self):
Install = self.app.controllers.Install await self.app.controllers.Install.install_task
await Install.install_task
await self.app.controllers.Late.run_event.wait() await self.app.controllers.Late.run_event.wait()
await self.copy_logs_to_target() await self.copy_logs_to_target()
self.server_reboot_event.set()
async def _run(self):
await self.server_reboot_event.wait()
if self.app.interactive: if self.app.interactive:
await self.user_shutdown_event.wait() await self.user_shutdown_event.wait()
self.shutdown() self.shutdown()
@ -86,6 +98,7 @@ class ShutdownController(SubiquityController):
if self.opts.dry_run: if self.opts.dry_run:
self.app.exit() self.app.exit()
else: else:
if platform.machine() == 's390x': if self.app.state == ApplicationState.DONE:
run_command(["chreipl", "/target/boot"]) if platform.machine() == 's390x':
run_command(["chreipl", "/target/boot"])
run_command(["/sbin/reboot"]) run_command(["/sbin/reboot"])