From b917dc466afa1c2e6cde2aed61ec7d6dedd257bb Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 25 Jul 2022 14:30:45 -0700 Subject: [PATCH] Implement stop on the ruby internal service --- .../commands/serve/service/internal_service.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/commands/serve/service/internal_service.rb b/plugins/commands/serve/service/internal_service.rb index 6325f671a..d9050338a 100644 --- a/plugins/commands/serve/service/internal_service.rb +++ b/plugins/commands/serve/service/internal_service.rb @@ -10,6 +10,7 @@ module VagrantPlugins module CommandServe module Service class InternalService < ProtoService(Hashicorp::Vagrant::RubyVagrant::Service) + def get_plugins(req, _) plugins = [] plugin_manager = Vagrant::Plugin::V2::Plugin.local_manager @@ -42,6 +43,21 @@ module VagrantPlugins ) end + def stop(_, _) + if !VagrantPlugins::CommandServe.server.nil? + logger.info("stopping the Vagrant Ruby runtime service") + # We want to hop into a separate thread and pause for a moment + # so we can send our response, then stop the server. + Thread.new do + sleep(0.05) + VagrantPlugins::CommandServe.server.stop + end + else + logger.warn("cannot stop Vagrant Ruby runtime service, not running") + end + Empty.new + end + def parse_vagrantfile(req, _) parse_item_to_proto(req.path.to_s) end