-1

I have a HaProxy load balancer on front of some IIS webservers. Haproxy checks the iis apps on a specific path if they are up or in maintenance.

I would like to make a solution, where I can safely reboot a random IIS machine and then have this to trigger my iis application to:

  1. React to the reboot and return a certain response code (a 404 in this case) on a specific path
  2. Stall the host machine reboot for 15 seconds to ensure all calls have been dealt with and that haproxy has seen this 404-status code signalling an upcoming reboot of the iis server.

Is it in any way possible to do these two things?

Windows Server 2016, .Net 4.7.2

This will not work, as all calls to the IIS will return "Service unavailable" when the IIS is running the Application_End code:

protected void Application_End()
{
  var log = SystemLogManager.GetLogger(GetType());
  try
  {
    log.Warn("Ending application. Hanging for 15 seconds...");
    Thread.Sleep(TimeSpan.FromSeconds(15));
    log.Warn("Done end");
  }
  catch(Exception ex)
  {
    log.Error("Unexpected error in application end", ex);
  }
}
Stephan Møller
  • 1,247
  • 19
  • 39
  • if the system is going trying to temporarily halt it is likely to end in IIS just being terminated by the kernel. – Mgetz May 21 '19 at 19:54
  • What's wrong with the 503? https://en.m.wikipedia.org/wiki/List_of_HTTP_status_codes – Stefan May 21 '19 at 21:08
  • @Stefan Well haproxy has an explicit feature that interpretes 404 as "going down for maintenance". If I just let the IIS return 503 on reboot then haproxy may still send trafic to the site before it realises that the server is permanently down (until the reboot is done). I went with a powershell identical to the accepted answer by bdn02 – Stephan Møller May 22 '19 at 06:42

1 Answers1

2

You can write a powershell script that you can call on any server and:

  • Make a webrequest to the check page that set a cache variable "logoffinprogress"
  • The check page check the cache variable and respond with a 404 http error code
  • The powershell script wait for 15 seconds and then reboot the server
  • On server restart iis is working and the checkpage respond with http 200 code

I hope that this can help you

bdn02
  • 1,500
  • 9
  • 15