Thanks, I'm almost there but having problems getting the role to deploy/start when I enable the startup task - it just goes into a loop of attempting to start, then recovering and trying again.
My .csdef file is as below:
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="MyWebRole" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WebRole ...>
...
<Startup>
<Task commandLine="Startup\StartupTasks.cmd" executionContext="elevated" taskType="simple" />
</Startup>
</WebRole>
</ServiceDefinition>
And then I have an ANSI encoded .cmd file in the WebRole project (Build Action: None, Copy to Output Directory: Copy always):
@echo off
@echo Installing "IPv4 Address and Domain Restrictions" feature
%windir%\System32\ServerManagerCmd.exe -install Web-IP-Security
@echo Unlocking configuration for "IPv4 Address and Domain Restrictions" feature
%windir%\system32\inetsrv\AppCmd.exe unlock config -section:system.webServer/security/ipSecurity
@echo Getting the name for the WebRole site (note: assumes there is only one site)
for /F "tokens=*" %%i in ('%windir%\system32\inetsrv\appcmd list site /text:name') do set sitename=%%i
@echo The site name is %sitename%
@echo Setting access restrictions for the Admin directory
%windir%\system32\inetsrv\AppCmd.exe set config "%sitename%/Admin" /section:ipSecurity /allowUnlisted:false
%windir%\system32\inetsrv\AppCmd.exe set config "%sitename%/Admin" /section:ipsecurity /+"[ipaddress='555.555.555.555',allowed='true']"
However, this only works if I:
- Comment out the <Startup>
section of the .csdef file
- Deploy to Azure
- Remote desktop into both of the instances
- Execute E:\approot\bin\Startup\StartupTasks.cmd from an elevated command prompt
I'm not sure why this isn't working automatically via the <Startup>
section.
I'm sure the path to the .cmd file is correct because if I put anything else, Visual Studio fails when I publish, saying it can't find the .cmd file.
Any ideas what could be causing the problem and how I can diagnose it? Is there a time limit for startup tasks - the .cmd file takes a good few minutes to run. Though I did one test with an empty .cmd file and it still seemed to fail.
If it helps, I've attempted a deployment (Deployment ID: a9b3c31e9ad04d97a593c00ec308afca) with the Startup section enabled.