If you experience your Windows Azure application based startup task or OnStart code does not work correctly, here are a few things you can try to investigate this issue:

  1. Add some of the diagnostics trace messages in your OnStart() function which will be sent to Azure Table Storage.
  2. You can also add diagnostics code in your startup task batch file which can send these logs to Azure Storage directly.
  3. Be sure to have Remote Desktop connection is enabled in your role. If you haven’t see the link below:
    1. http://blogs.msdn.com/b/avkashchauhan/archive/2011/04/03/setting-rdp-access-in-windows-azure-application-with-windows-azure-sdk-1-3-1-4.aspx
  4. Deploy to your Azure application in the staging slot (you sure can deploy to production slot and test the same, here deployment slot is your choice)
  5. Login to your Azure Application Role Instance using Remote Desktop Setting
  6. Now go ahead and kill the role host process (Note: Use this step with your test service, using this step with live service will cause service outage)
    1. For Web Role – WaWebHost.exe
    2. For Worker Role – WaWorkerHost.exe
  7. Step #4 will cause app agent to restart your role host process which will launch your startup task and/or onStart code.
  8. Now you can look for the startup task execution and OnStart trace messages to understand why there were errors.
  9. You can also open command prompt in the same approot working folder and launch your startup task batch file to see how it behave.
  10. if you have to execute two separate commands in startup task and there is a dependency between output of first command and execution of the second command, you can use two startup tasks in your application configuration with "Simple" setting this way all of your start up tasks execute in order. Please remember to exit each startup task batch file properly.

 

You can read more on Startup task in the blog below:

http://blogs.msdn.com/b/avkashchauhan/archive/2011/03/17/using-startup-task-in-windows-azure-detailed-summary.aspx