Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get IIS site to start up automatically after deployment?

I have a Web API service that I'm deploying to my various environments (using Octopus Deploy). It is supposed to do various tasks on startup, e.g. run any migration scripts required by Entity Framework Code First, and some background tasks managed by Hangfire. Trouble is, the web site only wakes up the first time someone makes a call to it. I want it to run as soon as I've deployed it. I could do it manually just by pointing a web browser at the API's home page, but that requires me to remember to do that, and if I'm deploying to multiple tentacles, that's a major PITA.

How can I force the web site to start up automatically, right after it's been deployed?

like image 483
Shaul Behr Avatar asked Nov 29 '15 14:11

Shaul Behr


People also ask

How do I make IIS start automatically?

Open Internet Information Services (IIS) Manager. In the Connections pane, select the Application Pools node, revealing the Application Pools pane in the main view. Select the application pool for which you wish to enable Auto-Start. Locate the Start Mode option under the General group and set it to AlwaysRunning.

What is IIS preload?

Application preload features in IIS allows applications to automatically start without a request. To implement this functionality you need to set the preloadEnabled property in the applicationHost.config.

How do I publish my website on IIS?

In IIS, right-click the Default Web Site, choose Deploy > Configure Web Deploy Publishing. If you don't see the Deploy menu, see the preceding section to verify that Web Deploy is running. In the Configure Web Deploy Publishing dialog box, examine the settings. Click Setup.

Why does APP pool stop automatically?

This issue occurs when the IIS application pool Identity Parameter is not set to NetworkService. To resolve this issue, change the Identity parameter to NetworkService in the IIS Manager for Windows Server: Select the Advanced Settings for the DefaultAppPool.


2 Answers

In the control panel under turn windows features on or off, Under "Web Server (IIS) | Web Server | Application Development", select "Application Initialization".

In IIS, on the advanced settings for the Application Pool, "Start Mode" should be set to "AlwaysRunning".

In IIS, on the advanced settings for the site, "Preload Enabled" should be set to "true".

A new deployment will cause it to start again (possibly after a short delay).

like image 155
Daniel Avatar answered Oct 15 '22 00:10

Daniel


You can use the Application Initialization Module for this, as many answers have mentioned, but there are a couple of benefits to dropping in a PowerShell step to your deployment...

  1. It can warm up your site
  2. It can act like a very basic smoke test
  3. If it fails, the deployment is marked as failed in Octopus

I use this PowerShell script to warm up and check websites after deployment.

Write-Output "Starting"

If (![string]::IsNullOrWhiteSpace($TestUrl)) {
    Write-Output "Making request to $TestUrl"

    $stopwatch = [Diagnostics.Stopwatch]::StartNew()
    $response = Invoke-WebRequest -UseBasicParsing $TestUrl -MaximumRedirection 0
    $stopwatch.Stop()

    $statusCode = [int]$response.StatusCode

    If ($statusCode -ge 200 -And $statusCode -lt 400) { 
        Write-Output "$statusCode Warmed Up Site $TestUrl in $($stopwatch.ElapsedMilliseconds)s ms"

        $stopwatch = [Diagnostics.Stopwatch]::StartNew()
        $response = Invoke-WebRequest -UseBasicParsing $TestUrl -MaximumRedirection 0
        $stopwatch.Stop()

        $statusCode = [int]$response.StatusCode
        Write-Output "$statusCode Second request took $($stopwatch.ElapsedMilliseconds)s ms"
    } Else {
        throw "Warm up failed for " + $TestUrl
    }
} Else {
    Write-Output "No TestUrl configured for this machine."
}

Write-Output "Done"
like image 44
Fenton Avatar answered Oct 15 '22 00:10

Fenton