3

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:

  1. Stop the site
    • in IIS Manager, select the site, click Stop
  2. Recycle the app pool the backend service runs in
    • in IIS Manager, select the application pool, click Recycle
  3. 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"
  4. 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?

10
  • Maybe you could enable logging to understand what is happening : appcmd set config /section:httpLogging /dontLog:False
    – krisFR
    May 10, 2015 at 22:01
  • Are you certain the curl is actually executing the service method in the way it should? I don't know curl very well, but I'm betting your testing would have exposed any HTTP 500s by now, but not knowing the guts of your service, it's possible that that step is not actually doing what it's supposed to.
    – nateirvin
    May 14, 2015 at 14:33
  • Have you tried replacing the appcmd statements with Powershell commands? technet.microsoft.com/en-us/library/ee790599.aspx I understand that figuring out what the problem is will provide a great sense of relief and accomplishemnt, and switching to Powershell might be a "workaround" instead of a solution, so I'm just making the suggestion in case you just want it to work right regardless. May 14, 2015 at 15:21
  • 1
    @nateirvin - That's where I had my doubts at first. But two things convince me that's not the problem: Fiddler traffic is identical with curl as with IE (request and response). Second, if I use IIS to stop/start the site and appPool but use curl to execute call the web method, it works. If I use appcmd to stop/start and IE to call the web method, it behaves as the script itself does. Not conclusive proof, but very compelling.
    – biscuit314
    May 14, 2015 at 19:52
  • Might help to do it manually on the command line before scripting it. Do a list before/after each command to make sure names/states are what is expected.
    – Brian
    May 14, 2015 at 22:29

1 Answer 1

0

What are the permissions for the user account that is running the script.

I assume you are an Administrator, but is the script runtime account also an Administrator level account?

Check that....

2
  • As you said in OP comments, if it was permissions it would always fail.
    – biscuit314
    May 20, 2015 at 21:20
  • agreed -- provided the script runtime account was the same each time - should there be more than one account involved - this could be worth looking at..... like running the script from CL, and then from a scheduler could involve multiple runtime accounts. Something else to check. May 20, 2015 at 21:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .