The Core Technologies Blog

Professional Software for Windows Services / 24×7 Operation


Q&A: How do I Test the “Check Web Server” Sanity Check?

Q&A - Test Web Server
  I’ve already started the trial of the Service Protector and I’m comfortable with the way it is working. I manually stopped my web service and Service Protector started it up right away.

I’m specifically interested in detecting some nasty 502 errors and downloaded the check website BAT file.

Any suggestions on how to simulate or force a 502? My test environments rarely crash (of course) and I need to gain a little bit of confidence before applying to one of our big customers.

— Greg

Hi Greg, thanks for trying Service Protector.

After discussing with our team, here are three ways you can test:

1. Specify a non-working URL

To make the sanity check work, you had to specify your server’s URL in the batch file (in the SET url line).

For example:

      SET url=http://localhost:8080

To confirm that your service will be promptly restarted when the sanity check fails, simply specify a bogus URL in the batch file.

An invalid URL will cause the URL ping to fail and signal Service Protector to restart your Windows Service — every time the sanity check runs.

To perform this test:

  1. Open the batch file in your favorite text editor

  2. Update the SET url line with a URL that does not point to an actual site

  3. Save the batch file

  4. Launch Service Protector

  5. Highlight your web server service and select Application > Start Protector

  6. Wait for the sanity check to be run (as per the frequency you provided when you setup the sanity check)

  7. Validate that your service is stopped and restarted, as expected

2. Update your web application to return a 502

The previous test applies to all failures, not only 502 errors.

If you have control of your web site code — in Laravel, Django, ASP.NET or another dynamic framework — you can create a URL endpoint that simply returns 502.

Put that URL that into the check website batch file (in the SET url line) and your service should be restarted whenever Service Protector runs the sanity check.

3. Use the free webhook service

If you don’t want to mess with your web site, we recommend use the free webhook service to create a URL that always returns a 502. If you place that URL in your batch file, your service should be restarted every time the sanity check is run.

To create the endpoint:

  1. Open this page in your browser: https://webhook.site/

    A unique URL will be created automatically for you:

    Create a Webhook URL
  2. This URL is immediately usable, but it will return HTTP Status code 200 by default. Click the Edit button and change the Default status code to 502. You might as well put in some response text, to explicitly signal what the URL does too:

    Set the Webhook default status code to 502

Visit the URL to ensure that it is responding as expected:

Check that the Webhook URL returns 502

Note that the URL won’t be available forever. From the Webhook.site Terms of use:

  For non-Premium URLs, data may be automatically deleted after a maximum of 7 days.

So you’ll have to purchase a premium offering if you want the URL to persist.

Happy testing!

Posted in Service Protector | Tagged , , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *