I have an Azure PaaS instance running a Spring-Boot packaged 'war' inside a Tomcat8 container. The problem is that, after a period of in-activity, the 'java' process is killed.
The above image is how it should look like when the tomcat process is not killed.
The tomcat process again starts only when I again make any sort of request to the server.
If my understanding is correct, the flag 'WEBSITE_SCM_ALWAYS_ON_ENABLED' is for the instance to stay alive i.e. the 'w3wp' process and not for Tomcat.
One solution to this problem is to 'poll' my server with a simple 'health' request to keep it alive.
It would be better if there was some Azure configuration or Spring-boot configuration for its 'httpPlatformHandler' so that I can prevent it from going to sleep.
Any help is appreciated.
**** UPDATE ****
With further help from @DavidEbbo, the problem was traced to a URL 'rewrite' rule that I had for going from 'http' to 'https' urls. The 'AlwaysOn' request is on HTTP (Port 80) and thus whenever the Azure request was being hit, it was getting a redirect(301) as a response. Still awaiting a solution.
The root of the problem is that the URL rewrite rule that you are using to redirect http to https is preventing the AlwaysOn warmup requests from reaching your Java app.
Luckily, there is a solution.
Use the following steps:
applicationHost.xdt
file under your 'site' folder (i.e. d:\home\site\applicationHost.xdt
). Hint: you can type touch applicationHost.xdt
in Kudu Console to create an empty file.Note that the AlwaysOn requests will still look like 301s in the http logs, but the right thing will still happen (i.e. Java will wake up).
Alternatively, if you don't want to use an XDT transform and want to keep everything in your web.config, you can just add the missing pieces there. Specifically, you'll need two changes (matching the XDT above):
Add this condition to your rewrite rule:
<add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
Add this applicationInitialization
section under system.webServer
:
<applicationInitialization>
<add initializationPage="/" />
</applicationInitialization>
But I suggest the XDT approach as it doesn't require tricky edits, and keeps those 'messy' things separate from your code base.
The correct way to enable Always On is to set it to On in the Azure portal. WEBSITE_SCM_ALWAYS_ON_ENABLED
is not something that you can set, but it's something that Azure sets as a result of enabling Always On.
Once you enable Always On, the root of your site (i.e. /
) will be hit every few minutes, which should keep it alive.
If you need additional paths to be hit, you can use applicationInitialization. More details here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With