diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/restart.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/restart.cpp index 48eb4fa014a..5c356f62159 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/restart.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/restart.cpp @@ -71,10 +71,25 @@ Result CvdDeviceRestartCommandHandler::Handle( std::vector subcmd_args = request.SubcommandArguments(); CF_EXPECT(ConsumeFlags(options.Flags(), subcmd_args)); - auto [instance, unused] = + auto [instance, group] = CF_EXPECT(selector::SelectInstance(instance_manager_, request), "Unable to select an instance"); + const auto& instances = group.Instances(); + if (!instances.empty() && instance.id() == instances[0].id()) { + bool other_active = false; + for (const auto& inst : instances) { + if (inst.id() != instance.id() && inst.IsActive()) { + other_active = true; + break; + } + } + CF_EXPECTF(!other_active, + "Restarting the first instance (ID: {}) is not allowed " + "while other instances are running. Restart the entire group instead.", + instance.id()); + } + CF_EXPECT( instance.Restart(std::chrono::seconds(options.wait_for_launcher_seconds), std::chrono::seconds(options.boot_timeout_seconds)));