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:
- Add some of the diagnostics trace messages in your OnStart() function which will be sent to Azure Table Storage.
- You can also add diagnostics code in your startup task batch file which can send these logs to Azure Storage directly.
- Be sure to have Remote Desktop connection is enabled in your role. If you haven’t see the link below:
- 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)
- Login to your Azure Application Role Instance using Remote Desktop Setting
- 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)
- For Web Role – WaWebHost.exe
- For Worker Role – WaWorkerHost.exe
- Step #4 will cause app agent to restart your role host process which will launch your startup task and/or onStart code.
- Now you can look for the startup task execution and OnStart trace messages to understand why there were errors.
- You can also open command prompt in the same approot working folder and launch your startup task batch file to see how it behave.
- 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: