Skip to content

Support per-instance stop in stop_cvd#2614

Open
SuperStrongDinosaur wants to merge 3 commits into
google:mainfrom
SuperStrongDinosaur:backend_stop
Open

Support per-instance stop in stop_cvd#2614
SuperStrongDinosaur wants to merge 3 commits into
google:mainfrom
SuperStrongDinosaur:backend_stop

Conversation

@SuperStrongDinosaur
Copy link
Copy Markdown
Collaborator

@SuperStrongDinosaur SuperStrongDinosaur commented May 28, 2026

Summary

Currently, stop_cvd indiscriminately stops all Cuttlefish instances. This change introduces granular control, allowing users to stop a specific instance (or list of instances) in a running group without affecting others.

Changes

stop_cvd update: Introduced the --instance_nums flag to stop_cvd. It accepts a comma-separated list of instance IDs to stop.
Instance Filtering: Updated the main loop in stop_cvd to check the --instance_nums set. If populated, it only sends the termination signal to instances matching those IDs.
cvd stop Integration: Modified the cvd stop command handler to parse selectors. It resolves targeted instance names to their IDs and propagates them as --instance_nums to the stop_cvd backend.
API Propagation: Updated InstanceManager::StopInstanceGroup and RunStopCvd to accept and pass the instance_nums string.
Database Status Update Fix: Updated StopInstanceGroup in instance_manager.cpp to only set the state to STOPPED in the database for the instances that were actually targeted and stopped.

Bug

b/459780275

Document

go/cuttlefish-per-instance-control

Frontend pr

#2615

@SuperStrongDinosaur SuperStrongDinosaur changed the title feat(backend): support per-instance stop in stop_cvd Support per-instance stop in stop_cvd May 28, 2026
@SuperStrongDinosaur SuperStrongDinosaur added the kokoro:run Run e2e tests. label May 28, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label May 28, 2026
@SuperStrongDinosaur SuperStrongDinosaur marked this pull request as ready for review June 1, 2026 12:54
Copy link
Copy Markdown
Member

@jemoreira jemoreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not very useful unless cvd start also supports specific instances. Are you planning to implement that too?

Comment thread base/cvd/cuttlefish/host/commands/stop/main.cc
Comment thread base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.h Outdated
Comment thread base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.cpp Outdated
Comment thread base/cvd/cuttlefish/host/commands/cvd/cli/commands/stop.cpp Outdated
@SuperStrongDinosaur
Copy link
Copy Markdown
Collaborator Author

This is not very useful unless cvd start also supports specific instances. Are you planning to implement that too?

Yes, I am currently finishing up cvd start changes also

std::vector<std::future<int>> exit_state_futures;
exit_state_futures.reserve(instances.size());
for (const auto& instance : instances) {
unsigned id;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC stopping the first instance causes all other instances to stop too (or crash). Did you test that case?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this myself and can confirm that stopping the first one also kills the second one (becomes unreachable). I think you're going to have to land the separate starts before being able to land this one.

You probably already know this, but just in case: The first instance runs some services that are used by all instances. To support this feature you're likely going to have to extract those to run as a standalone thing as part of the group.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware of this issue. I plan to introduce validation in a separate PR to prevent cvd stop and cvd restart from executing on the main instance, as doing so currently crashes all other instances.

Long-term, the ideal solution is to extract those daemons from the main instance. However, that is highly complex :), and we need the ability to manipulate instances separately within a reasonable timeframe. Given that this specific limitation isn't a blocker for our use case, the validation check is the best step for now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to introduce validation in a separate PR

Would rather see it in this PR. stop/main.cc can already load the CuttlefishConfig structure, which reports what the first instance id is. Something like

CuttlefishConfig::Get()->Instances()[0].id()

should produce the first instance id.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the check that prevents main instance to stop. Also I created a separate pr with this change for cvd restart
#2649

Comment thread base/cvd/cuttlefish/host/commands/cvd/cli/commands/stop.cpp Outdated
Comment thread base/cvd/cuttlefish/host/commands/cvd/cli/commands/stop.cpp Outdated
Comment thread base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.cpp Outdated
Comment thread base/cvd/cuttlefish/host/commands/cvd/instances/stop.cpp Outdated
Comment on lines +102 to +104
CF_EXPECTF(!instances.empty(), "Instance '{}' not found in group '{}'",
name, group.GroupName());
instance_nums.push_back(instances.front().id());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than looking only at instances.front(), can it either validate that instances.size() == 1 or apply to every member of instances?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants