I understand that startup tasks are used to set up your system. For example, if your code is written in Python, you can add a startup task to install Python. But can't this also be done in the ProgramEntryPoint batch script? What's the difference?
-
I once had to use a start-up script to install the Visual C++ 2010 Runtime library since it's not available by default on Azure, and it needed an elevated context to do that, so that's one example. – Shahin Dohan Jul 27 '12 at 12:25
3 Answers
Its true that, if you use the ProgramEntryPoint there doesn't seem to be a reason to use startup tasks. You can indeed include all the logic in that same batch file.
Startup tasks get more useful when working with the .NET WebRoles/WorkerRoles. There you only have the option to write code (where you could again call a single batch file calling other batch files) and or use startup tasks.
But if you look at it from a maintenance point of view its much cleaner to use startup tasks for everything having to do with configuration and installation of your instance. You draw a clear line between configuration/installation and your actual application - you could actually see this as separation of concerns (this will be easy to understand be other/new developers on the project).
Besides that you have to know that, when you use tasks, you can execute tasks in different contexts (limited / elevated) which might be important from a security perspective. And tasks exist in different types (simple, background, foreground) which can be used in many different scenarios (a background app that constantly pings your site for example). If you don't use tasks, you might need to handle all of this yourself.
Here is a good blog post covering the details of startup tasks: Using Startup Task in Windows Azure detailed summary

- 24,739
- 2
- 60
- 65
Great answer from Sandrino. In a nutshell - you would use startup tasks if you want some code to execute (or start executing) before your role starts. If that is not a constraint you can always execute any process (including batch scripts) from the OnStart method of the Role. One case where I have used startup tasks in the past is to install the NewRelic monitoring agent. I wanted that running to profile my app before the actual app started.

- 458
- 2
- 7
You will probably not be able to install Python from the ProgramEntryPoint since the install will probably require elevated ("admin") privilegies.
A role (web/worker) usually does not have elevated privilegies (it might be possible but it is a bad practice for obvious security reasons). So code in ProgramEntryPoint does not have elevated privilegies.
On another hand, a startup task can have elevated privilegies. IMO, this probably the biggest (single ?) benefit from using startup tasks.

- 1,815
- 13
- 11