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" )