Edit

Share via


Shut down Orleans silos

This article explains how to gracefully shut down an Orleans silo before the app exits. This applies to apps running as a console app, or as a container app. Various termination signals can cause an app to shut down, such as Ctrl+C (or SIGTERM). The following sections explain how to handle these signals.

Graceful Silo shutdown

The following code shows how to gracefully shut down an Orleans silo console app. Consider the following example code:

C#
using Microsoft.Extensions.Hosting;
using Orleans;
using Orleans.Hosting;

await Host.CreateDefaultBuilder(args)
    .UseOrleans(siloBuilder =>
    {
        // Use the siloBuilder instance to configure the Orleans silo.
    })
    .RunConsoleAsync();

The preceding code relies on the Microsoft.Extensions.Hosting, and Microsoft.Orleans.Server NuGet packages. The RunConsoleAsync extension method, extends IHostBuilder to help manage the lifetime of the app accordingly, listening for process termination signals and shutting down the silo gracefully.

Internally, the RunConsoleAsync method calls UseConsoleLifetime which ensures that the app shuts down gracefully. For more information on host shutdown, see .NET Generic Host: Host shutdown.

See also