have clicking restart in an error view restart the server too
This commit is contained in:
parent
913a5262a2
commit
3458227e94
|
@ -28,6 +28,10 @@ class API:
|
|||
def GET() -> ApplicationState:
|
||||
"""Get the installer state."""
|
||||
|
||||
class restart:
|
||||
def POST() -> None:
|
||||
"""Restart the server process."""
|
||||
|
||||
class dry_run:
|
||||
"""This endpoint only works in dry-run mode."""
|
||||
|
||||
|
|
|
@ -147,6 +147,7 @@ class Subiquity(TuiApplication):
|
|||
|
||||
self.help_menu = HelpMenu(self)
|
||||
super().__init__(opts)
|
||||
self.restarting_server = False
|
||||
self.prober = Prober(opts.machine_config, self.debug_flags)
|
||||
journald_listen(
|
||||
self.aio_loop, ["subiquity"], self.subiquity_event, seek=True)
|
||||
|
@ -206,13 +207,33 @@ class Subiquity(TuiApplication):
|
|||
# And remove the overlay.
|
||||
self.remove_global_overlay(install_running)
|
||||
|
||||
def restart(self, remove_last_screen=True):
|
||||
async def _restart_server(self):
|
||||
log.debug("_restart_server")
|
||||
try:
|
||||
await self.client.meta.restart.POST()
|
||||
except aiohttp.ServerDisconnectedError:
|
||||
pass
|
||||
self.restart(remove_last_screen=False)
|
||||
|
||||
def restart(self, remove_last_screen=True, restart_server=False):
|
||||
log.debug(f"restart {remove_last_screen} {restart_server}")
|
||||
if remove_last_screen:
|
||||
self._remove_last_screen()
|
||||
if restart_server:
|
||||
self.restarting_server = True
|
||||
self.ui.block_input = True
|
||||
self.aio_loop.create_task(self._restart_server())
|
||||
return
|
||||
if remove_last_screen:
|
||||
self._remove_last_screen()
|
||||
if self.urwid_loop is not None:
|
||||
self.urwid_loop.screen.stop()
|
||||
self.urwid_loop.stop()
|
||||
cmdline = ['snap', 'run', 'subiquity']
|
||||
if self.opts.dry_run:
|
||||
if self.server_proc is not None and not restart_server:
|
||||
print('killing server {}'.format(self.server_proc.pid))
|
||||
self.server_proc.send_signal(2)
|
||||
self.server_proc.wait()
|
||||
cmdline = [
|
||||
sys.executable, '-m', 'subiquity.cmd.tui',
|
||||
] + sys.argv[1:]
|
||||
|
@ -320,6 +341,9 @@ class Subiquity(TuiApplication):
|
|||
|
||||
def _exception_handler(self, loop, context):
|
||||
exc = context.get('exception')
|
||||
if self.restarting_server:
|
||||
log.debug('ignoring %s %s during restart', exc, type(exc))
|
||||
return
|
||||
if isinstance(exc, Abort):
|
||||
self.show_error_report(exc.error_report_ref)
|
||||
return
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from aiohttp import web
|
||||
|
||||
|
@ -41,6 +43,9 @@ class MetaController:
|
|||
async def status_GET(self) -> ApplicationState:
|
||||
return self.app.status
|
||||
|
||||
async def restart_POST(self) -> None:
|
||||
self.app.restart()
|
||||
|
||||
|
||||
class SubiquityServer(Application):
|
||||
|
||||
|
@ -82,3 +87,11 @@ class SubiquityServer(Application):
|
|||
async def start(self):
|
||||
await super().start()
|
||||
await self.start_api_server()
|
||||
|
||||
def restart(self):
|
||||
cmdline = ['snap', 'run', 'subiquity']
|
||||
if self.opts.dry_run:
|
||||
cmdline = [
|
||||
sys.executable, '-m', 'subiquity.cmd.server',
|
||||
] + sys.argv[1:]
|
||||
os.execvp(cmdline[0], cmdline)
|
||||
|
|
|
@ -278,7 +278,7 @@ class ErrorReportStretchy(Stretchy):
|
|||
self.app.debug_shell()
|
||||
|
||||
def restart(self, sender):
|
||||
self.app.restart()
|
||||
self.app.restart(restart_server=True)
|
||||
|
||||
def view_report(self, sender):
|
||||
self.app.run_command_in_foreground(["less", self.report.path])
|
||||
|
|
Loading…
Reference in New Issue