3
votes

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?

2

2 Answers

1
votes

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>
0
votes

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