3

I have an Azure Cloud Service that requires some warm up when an application pool comes online (typically 5-10 minutes). Because of this, I like to schedule an IIS\App Pool recycle during off hours. When my recycle takes place mid-day, I get users yelling at me (and I prefer to not get yelled at)

What I've been doing is remoting into the VM, add a cmd file to a local disk and create a scheduled task that runs the cmd file:

net stop "World Wide Web Publishing Service"
net start "World Wide Web Publishing Service"

My problem is, periodically PaaS services get "refreshed", so randomly, any code\files I manually publish to a cloud service VM disappear. I need to remote back into the machines and re-add my cmd and scheduled tasks.

I know cloud services allow you to run startup tasks and the like. Can I do something similar to startup tasks that would allow me to package this cmd file when I publish my app, but schedule these commands externally? If so.. how?

David Makogon
  • 69,407
  • 21
  • 141
  • 189
ewitkows
  • 3,528
  • 3
  • 40
  • 62

2 Answers2

1

Startup tasks may execute any unattended app/installer you include in your .cspkg. You need to make sure the cmd file in question is bundled properly (e.g add configureSchedule.cmd to project, make sure it's copied to output directory).

Since you're attempting to set up scheduling, you'll likely need to run your cmd in elevated mode:

<Startup>
    <Task commandLine="configureSchedule.cmd" executionContext="elevated" taskType="simple" >
        <Environment>
            <Variable name="MyVersionNumber" value="1.0.0.0" />
        </Environment>
    </Task>
</Startup>
David Makogon
  • 69,407
  • 21
  • 141
  • 189
0

The better solution is to change the AppPool settings to recycle at a specific time. Do this from a startup script like David Makogan mentioned.

Take a look here: Set default app pool recycling via command line

Set the recycling time: https://www.iis.net/configreference/system.applicationhost/applicationpools/add/recycling/periodicrestart

enter image description here

Be sure to uncheck the "regular time interval", otherwise there will be recycle events during the day.

Also, you are stopping the WWW service, a quicker way is to only recycle the application pool. That way a new application pool is started, while the old one handles the last request from users. So there is (almost) no connectivity loss

appcmd recycle apppool /apppool.name: Marketing 
Community
  • 1
  • 1
Erik Oppedijk
  • 3,496
  • 4
  • 31
  • 42
  • Thanks for the info @ErikOppedijk. My issue is, periodically the VM gets "reset", and custom changes I make - like manually adding a file to a drive on the cloud service VM - disappear. So currently, I need to remote back into the machine and retool manually, which is what Im trying to avoid. Additionally, thanks for the tip on the appcmd, but my app pool name is always randomly generated, which causes an issue for that solution unfortunately. – ewitkows Aug 02 '16 at 14:15
  • The above script must be placed in a startup script, like David mentioned. The advantage is that this is native IIS functionality. – Erik Oppedijk Aug 04 '16 at 07:09