all Technical posts

Restart Azure Service Fabric service with code

In this post I will show you how you can restart a Service Fabric service from code

Currently I’m working on a Azure Service Fabric implementation. The official documentation contains a lot of valuable information, but it can take you quite some time to find the right piece of code you are looking for.

Our Service Fabric framework contains dynamically created Stateless services where during service startup our “configuration service” returns cached configuration.

When service configuration updates occur, it is necassary to restart instances of all the service. You can achieve this by using the Observer-pattern.

I was looking into how you can restart a service from code but it took me quite some time to figure out how to achieve that. By using the following code you can restart a Stateless or Statefull service from within the service itself:

You can find the original code on GitHub.

It is good to know that this only works on unsecured clusters – If you deploy this to a secure cluster, the service should run with elevated permissions.

Happy Service Fabric programming!

Subscribe to our RSS feed