From e47abd629152bdce8b3565fdd36c9c15470e6cd6 Mon Sep 17 00:00:00 2001 From: nesitor Date: Tue, 23 Jul 2024 11:38:12 +0200 Subject: [PATCH] Solve Firecracker reboot issues (#658) Problem: If the frontend or a user send the request to reboot a Firecracker instance, it stops but doesn't start again. Solution: Change method to restart it just stopping the process, cleaning the firecracker run files and starting it again. --- src/aleph/vm/controllers/__main__.py | 2 +- src/aleph/vm/hypervisors/firecracker/microvm.py | 1 + src/aleph/vm/hypervisors/qemu/qemuvm.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/aleph/vm/controllers/__main__.py b/src/aleph/vm/controllers/__main__.py index 2ba923ab..90475086 100644 --- a/src/aleph/vm/controllers/__main__.py +++ b/src/aleph/vm/controllers/__main__.py @@ -91,7 +91,7 @@ async def handle_persistent_vm(config: Configuration, execution: Union[MicroVM, def callback(): """Callback for the signal handler to stop the VM and cleanup properly on SIGTERM.""" - loop.create_task(execution.teardown()) + loop.create_task(execution.stop()) loop.add_signal_handler(signal.SIGTERM, callback) diff --git a/src/aleph/vm/hypervisors/firecracker/microvm.py b/src/aleph/vm/hypervisors/firecracker/microvm.py index 14230f6e..e5a7c94d 100644 --- a/src/aleph/vm/hypervisors/firecracker/microvm.py +++ b/src/aleph/vm/hypervisors/firecracker/microvm.py @@ -181,6 +181,7 @@ def prepare_start(self): system(f"rm -fr {self.jailer_path}/dev/net/") system(f"rm -fr {self.jailer_path}/dev/kvm") system(f"rm -fr {self.jailer_path}/dev/urandom") + system(f"rm -fr {self.jailer_path}/dev/userfaultfd") system(f"rm -fr {self.jailer_path}/run/") if os.path.exists(path=self.vsock_path): diff --git a/src/aleph/vm/hypervisors/qemu/qemuvm.py b/src/aleph/vm/hypervisors/qemu/qemuvm.py index 384c31b0..53518eb0 100644 --- a/src/aleph/vm/hypervisors/qemu/qemuvm.py +++ b/src/aleph/vm/hypervisors/qemu/qemuvm.py @@ -146,6 +146,6 @@ def send_shutdown_message(self): print("shutdown message sent") client.close() - async def teardown(self): + async def stop(self): """Stop the VM.""" self.send_shutdown_message()