I have worked on a case where because a specific reason, it was needed to Flush DNS from the PaaS Cloud Service Instances each 8 hours. And this is completely possible, however, since we are talking about PaaS Cloud Services and we already know we can’t apply manual changes since the PaaS Instances are stateless, we will have to use Start up tasks and Windows Task Scheduler to get this done. Please see the following steps:
You will need to:
1) Create a cmd file named “flushdns.cmd” with the flush DNS command (ipconfig /flushdns) and any other that you want or need (this cmd file will be used by Task Scheduler to flush DNS)
2) Create another cmd file named “task-flushdns.cmd” and put a task scheduler command that set Task Scheduler to run the flushdns.cmd command file every 8 hours
Schtasks /create /tn FlushDNS /tr E:\approot\Startup\flushdns.cmd /sc hourly /mo 8 /ru System
a) This is the part of the command where the flushdns.cmd file is called “E:\approot\Startup\flushdns.cmd”
b) This command is set to be executed with System Account in “/rn System“
c) After following the step 3, this is the location where the flushdns.cmd will be “E:\approot\Startup\”
d) More details about setting Task Scheduler by command lines here.
3) For a Role (Web or Worker Role)
- In Solution Explorer, under Roles in the cloud service project right click on your role and select Add>New Folder. Create a folder named Startup
- Right click on the Startup folder and select Add>Existing Item. Select the flushdns.cmd and task-flushdns.cmd files and add them to the Startup folder.
4) Create a startup task in the ServiceDefinition.csdef: Now, you will have to create the startup task itself, and for this, you will need to Add the following to the ServiceDefinition.csdef file under the WebRole or WorkerRole node. For more information on startup tasks see: Run
Startup Tasks in Azure.
<Task commandLine="task-flushdns.cmd" executionContext="elevated" taskType="simple" />
Note: The above configuration will run the task-flushdns.cmd file which will configure Task Scheduler to run the flushdns.cmd command file, and re-run it after each 8 hours.