Issues stopping app pools during deploy when autoStart being used

We are using the application initialization feature by setting startMode=AlwaysRunning and preloadEnabled=True in the octo configuration. We are using custom installation paths.
We find that often, deploys while purging the folder because a worker process has the files locked.

This happens even though our Pre-deployment script creates an app_offline file as well as tries to stop the app pool (using Stop-WebAppPool). We find that the app pool reports it is in the “Stopping” state indefinitely (using Get-WebAppPoolState). Even after several hours it’s stuck in this state. If we look at worker processes we see there is indeed a process with filehandles open in the installation folder.

The issue goes away if we switch startMode=OnDemand.

Has anyone seen issues like this when using application initialization in IIS (IIS 8.5/Win 2012R2)?

This is an issue we ran into. Our solution was to include a custom deployment step at the beginning of the deployment. It is a “Deploy IIS WebSite” step that deploys a custom app offline page and web.config to the directory. Contained within the package is a PreDeploy.ps1 that stops the app pool. This allows the app pool to be stopped, then the site has it’s file contents wiped and replaced with the app offline package, and finally the site is brought up and running. The nice part is we made this a step template so it can be shared across multiple projects, and you merely enter the app pool name, website name, bindings, custom install dir, etc. just like you do for the actual IIS deployment.