public override async Task StopAsync(CancellationToken cancellationToken) { _logger.LogInformation("Stopping Service"); if (_server != null) { GrpcServerUtils.GracefullyStop(_server); } await base.StopAsync(cancellationToken); }
static void Main(string[] args) { try { IServiceHealth health; Grpc.Core.Server server = Run(args, out health); _msg.Info("Type Q(uit) to stop the server."); while (true) { // Avoid mindless spinning Thread.Sleep(100); if (System.Console.KeyAvailable) { if (System.Console.ReadKey(true).Key == ConsoleKey.Q) { _msg.Warn("Shutting down due to user input"); break; } } // TODO: Uncomment after next pull //if (health.IsAnyServiceUnhealthy()) //{ // _msg.Warn("Shutting down due to service state NOT_SERVING"); // break; //} } if (server != null) { GrpcServerUtils.GracefullyStop(server); } } catch (Exception ex) { _msg.Error("An error occurred in microservice.", ex); Environment.ExitCode = -1; } finally { _msg.Debug("License released, shutting down..."); } }