Search code examples
azure-service-fabric

Removing application from service fabric cluster


I tried removing application from service fabric using service fabric explorer.

I deleted my application using Delete Application action. Then When I tried Unprovision application type I got error saying,

Error: Application Type of version 1.0.0 could not be unprovisioned as it still contains active applications.

I could see that even after deleting the application , the actor service inside the application is still active in some of the nodes. Am attaching a screenshot of my service fabric explorer.

Any help regarding completely removing the applications?


Solution

  • This can happen if services in your application don't play nice by not shutting down when requested by the platform, for example by ignoring the cancellation token in RunAsync.

    Here's a quick PowerShell script that will go through an application and force remove all replicas of all stateful services:

    Connect-ServiceFabricCluster -ConnectionEndpoint localhost:19000
    
    $nodes = Get-ServiceFabricNode
    
    foreach($node in $nodes)
    {
        $replicas = Get-ServiceFabricDeployedReplica -NodeName $node.NodeName -ApplicationName "fabric:/MyApp"
    
        foreach ($replica in $replicas)
        {
            Remove-ServiceFabricReplica -ForceRemove -NodeName $node.NodeName -PartitionId $replica.Partitionid -ReplicaOrInstanceId $replica.ReplicaOrInstanceId
        }
    }