I've scratched my head raw on this. Please help me stop the scratching.
We have a manual workaround for a site problem we're experiencing. The workaround always works when we do the steps manually, but running a script that does the same steps sometimes works but usually doesn't. My question: Why would there be a difference between performing the steps manually and performing them under script?
The manual steps are:
- Stop the site
- in IIS Manager, select the site, click Stop
- Recycle the app pool the backend service runs in
- in IIS Manager, select the application pool, click Recycle
- Make a call to a method on the backend service. This is to prepopulate some data before bringing the site up. The backend service is a .asmx
- In Internet Explorer, navigate to the backend's method Invoke page, enter some parameters, click "Invoke"
- Start the site
- in IIS Manager, select the site, click Start
As I said, this always brings the site up with full functionality. This should be so scriptable, right?
So I write a batch script that essentially does this:
%windir%\system32\inetsrv\appcmd.exe stop site nameOfSite
%windir%\system32\inetsrv\appcmd.exe recycle apppool nameOfAppPool
curl...(call web method with headers and parameters identical to what IE does)
%windir%\system32\inetsrv\appcmd.exe start site nameOfSite
The curl
call appears identical in Fiddler to using IE to make the call. Further, I've replaced the curl
call with a pause so the script gives me a chance to use IE to call the web method. So I'm pretty sure it's not that line.
I've put delays between the steps.
I've tried starting/stopping the appPool (instead of a recycle).
I've tried doing the same thing with Python:
subprocess.check_output([params to call appcmd], shell=True)
None of these attempts changes the behaviour:
- each step reports success
- sometimes the site is actually up and everything is fine
- more often than not, the site goes back down after about a minute. This NEVER happens if I perform the steps through IIS and IE.
- occassionally the final step does not succeed and the site remains down.
When the script fails, merely re-running the script never works. I have to perform the steps manually then all is well.
This makes no sense to me. Does it to you? Is there an alternate to appcmd
that more closely does what IIS does in starting/stopping/recycling? What am I doing wrong?