Search code examples
azurestartupazure-web-roles

Microsoft Azure Startup Task Not Executing


I have a simple file in the root of my Web project (which is tied to a Web worker role). The file is named Startup.cmd. This file contains the following line: dir > directory.txt. It executes properly when I run it from the command line and outputs a list of the directory contents to file named directory.txt as you would expect. Similarly, the line ECHO Write this line to file > output.txt does not appear to work either.

Inside ServiceDefinition.csdef for my Azure Cloud Service project, I have the following lines:

<WebRole name="Website" vmsize="Small">
    <Startup>
        <Task commandLine="Startup.cmd" executionContext="elevated" taskType="simple"></Task>
    </Startup>
    ....
</WebRole>

I believe it is finding the file, because I have tried changing the path and it will throw a build error that it cannot find it. The issue is that when I check my /bin/ directory after debugging to the Azure Debugging Environment, I see Startup.cmd (I have it set to Copy always) but I do not see directory.txt. I'm not sure of another way to confirm that it executed properly.


Solution

  • I found the following MSDN article useful: http://msdn.microsoft.com/en-us/library/hh180155.aspx.

    As a result, I made some changes to my Startup.cmd file. I changed the command to:

    ECHO The current version is %MyVersionNumber% >> "%TEMP%\StartupLog.txt" 2>&1
    EXIT /B 0
    

    However, this did not appear to put the output in my temporary directory for my system: C:\Users\username\AppData\Local\Temp. I'm going to presume this is because the Azure Compute Emulator uses a different temp directory I am unaware of.

    I changed my Startup.cmd to:

    ECHO The current version is %MyVersionNumber% >> "c:\temp\StartupLog.txt" 2>&1
    EXIT /B 0
    

    And updated my configuration to:

    <WebRole name="Website" vmsize="Small">
      <Startup>
          <Task commandLine="Startup.cmd" executionContext="elevated" taskType="simple">
              <Environment>
                  <Variable name="MyVersionNumber" value="1.0.0.0" />
                  <Variable name="ComputeEmulatorRunning">
                      <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
                  </Variable>
              </Environment>
          </Task>
      </Startup>
      ...
    </WebRole>
    

    And this did appear to write the file to C:\temp\ upon starting the debugger.