19
1
I have a batch script that allows me to turn off a site, deploy files and turn the site back on.
- Stop the application pool - works
- Stop the website - works
- Deploy files - works
- Start Application Pool - works only sometimes!
- Start the website - works if previous works
I'm running Windows Server 2012 R2, and the batch script is executed by an Octopus Deploy tentacle.
The line it is failing on is:
Start-WebAppPool -Name $appPoolName
Where $appPoolName is live.website.com
This line works sometimes but not others, and is not consistent in any pattern.
I have the same script working on other servers. I have checked whether Application Information service is running and it is running fine. There are no system logs in the event viewer.
Although, I have this one application error which is raised when the Start-WebAppPool is called:
ERROR + Start-WebAppPool -Name $appPoolName
ERROR start-webitem : The service cannot accept control messages at this time.
Do anyone know why this may be happening? I have tried to write a do-while loop until it is in a "Started" state, but it loops forever failing.
Update
Turns out the process isn't stopping when I turn the Application pool off.
Why would the process continue to run after stopping the application pool? It literally continues running, without stopping.
Fixed!
So - following the comments below, when I stop the application pool I now make sure it is completely at stopped state before continuing the script.
This is the script I now have and is fully working:
# Load IIS module:
Import-Module WebAdministration
# Get AppPool Name
$appPoolName = $OctopusParameters['appPoolName']
if ( (Get-WebAppPoolState -Name $appPoolName).Value -eq "Stopped" )
{
Write-Host "AppPool already stopped: " + $appPoolName
}
else
{
Write-Host "Shutting down the AppPool: " + $appPoolName
Write-Host (Get-WebAppPoolState $appPoolName).Value
# Signal to stop.
Stop-WebAppPool -Name $appPoolName
}
do
{
Write-Host (Get-WebAppPoolState $appPoolName).Value
Start-Sleep -Seconds 1
}
until ( (Get-WebAppPoolState -Name $appPoolName).Value -eq "Stopped" )
1Sounds to me like you're issuing the App Pool stop command successfully, but it's not actually stopped by the time you try to start it again. Probably because the "process" that you mention in your edit is holding it in a running state (or perhaps in "stopping" state), waiting for something to finish. Is it always the same process holding it? What is that process? (System process, or part of your web app, or ???). If it's a process that apart of your web app, then why not debug it and figure out what it's waiting on (if anything)? – Ƭᴇcʜιᴇ007 – 2015-11-09T16:59:17.063
1As a stop-gap, perhaps add code to your script to wait until the app pool is actually in a stopped state before continuing on in the script? – Ƭᴇcʜιᴇ007 – 2015-11-09T17:01:07.090
2@Base33, can you paste the answer in an answer and mark is as the solution? Then this will no longer show up as "unanswered" – HackSlash – 2018-04-19T17:50:00.300