WorkerRole.cs what is its purpose - azure

Hi I have created a new azure project with a worker role and have noticed a class WorkerRole.cs. I tried researching on what it's purpose is however I couldn't find a straight answer.

The goal of the WorkerRole.cs is to give you an entry point to execute "something" when the Worker Role instance starts. This could be a command line application you're starting, or a WCF service, or MySQL, ... anything you want.
Note that you'll need to write code to keep the instance 'alive'. If you don't do this, it will restart when the Run method completes. Take a look at the following question for more information: Using Thread.Sleep or Timer in Azure worker role in .NET?

Here is something you can use to understand Windows Azure Worker Role:
Windows Azure is Platform as a Service and you will get to run your application in a dedicated virtual machine (except with extra-small instance)
The application architecture for Windows Azure application supports 3 different kind of applications called Web Role, Worker Role and VM Role,
2.1. A Web role is considered an application in which IIS is pre-configured and ready for your application. In most cases it is a web based application but it may not if you wish, but IIS will always be there. With IIS, you can run either an ASP.NET application or a node.js application it is your choice to decide what kind of application you would want.
2.2. A Worker role is considered to be an application which does not need IIS and it is up to you whatever you would want to run on Worker role, C#, Java, PHP, Python or anything else. It is mainly used for open source web application or an application which perform actions as back-end and does not need web front end.
2.3 VM Role is in BETA and used to run on a custom VHD deployed by user. We would consider it is in following explanation.
All of these roles are actually a libraries means they compiled as DLL and when they run on Windows Azure, they actually needs a host process to run. For Web Role, the host process is WaWebHost.exe or WaWebIIS.exe, for WorkerRole the host process is WaWorkerHost.exe.
When these host process starts in Windows Azure they look for a file call E:__entrypoint.txt which provided the Role DLL name and location so host process and find and load it.
These Web and Worker role class are derived from RoleEntryPoint base class which extend all of required function for a web and worker role to run in Windows Azure Environment
When you create a web or worker role using, Azure SDK template you will get these base code file where Web and Worker Role class can implement required functions. For Worker Role the call WorkerRole defined in WorkerRole.cs and for Web Role it is WebRole.cs.
If you decided to add code specific to Windows Azure Runtime i.e. configuration or some setting you are going to add here because when role will start via host process, the code you have added in WebRole.cs or WorkerRole.cs will execute in Windows Azure runtime context.

Related

How to execute appcmd on Azure Web App box?

I'd like to execute a
appcmd set config /commit:WEBROOT /section:sessionState /mode:StateServer /stateConnectionString: tcpip=loopback:42424 /stateNetworkTimeout: 120 /useHostingIdentity:True
command on the box belonging to an Azure Web App. The console is a "sandbox environment", so I don't necessarily expect to have enough privileges, but appcmd is not recognized as a command.
Same thing happened with the KUDU special console - which looked more promising in terms of potential privileges to carry out the task -, both with the CMD and the PowerShell console.
My main goal is to start the IIS's State Server. How to start ASP.Net State Service in Azure mentions "startup task", but I couldn't figure out how to do that. https://technet.microsoft.com/en-us/library/cc732412(v=ws.10).aspx quotes appcmd.
Per your link in your question: Startup tasks are for web/worker roles in Cloud Services, not Web Apps (completely different things; web/worker role instances are Windows Server instances, not a sandboxed environment).
You cannot enable IIS State Server on Web Apps. You'll need to store your session state in something like Redis Cache service, which runs independent of Azure Web Apps. Really, you can use any cache (or storage) you want that's external to the Web App sandbox, as long as you have proper drivers/providers for what you choose.

Is microsoft recreating PaaS VMs for Web / Worker Roles for each release?

I want to understand how does this Web / Worker role under cloud service work. As per my understanding, we have to define the required Web / Worker role instance count in CSDEF file, and Azure will create VMs (Instances) under the cloud service automatically. How about the application is updated and new code is deployed? Will the existing instances destroyed and new instances will be created or only the changed code will be updated in IIS? How does it work in the backend?
Note: Basically I have four instances in a web role and I want to create around 20 local user accounts in the VMs to manage it by different teams. I want to ensure the accounts do not get deleted whenever deployment is done.
Basically I have four instances in a web role and I want to create
around 20 local user accounts in the VMs to manage it by different
teams. I want to ensure the accounts do not get deleted whenever
deployment is done.
Simple answer: Don't Do This!
Azure Cloud Services are essentially Stateless Virtual Machines. What that means is that anything you do in the VM (like installing software etc.) after a VM is created for you can be removed. Though this doesn't apply when you simply deploy the new version of the code but there are times when Microsoft takes down faulty VMs and stand up new VMs for you automatically from the last package file you used to create/update the deployment. In this scenario, any changes you have made will be lost.
Cloud services should be considered stateless. The disks won't necessarily be destroyed on every deployment, but you must plan for it. Any configuration or operations you wish to perform prior to the role starting up must be defined as a startup task in the CSDEF file.

Deploy Worker Role To Azure VM

I have a Worker Role that need complex environment settings (install a couple of softwares, setup some directories and etc) so I want to deploy it to VM ( instead of Cloud Service that specialize in more simple environment without pre configure settings).
The problem that I can only publish to Cloud Service (from VS 2013), am I missing something ?
I tried to find some article and relevant materiel about deploy a Worker Role to a VM and the only things I found is related to the Cloud Service.
How can I do it ?
(or provide me a general guidelines)
Simply put, you can't deploy a Worker Role as is into an Azure Virtual Machine (IaaS) without doing code changes.
Things you could do:
Isolate your business logic into a separate DLL and then create a separate Windows Service project which consumes this DLL. Then you could deploy that Windows Service into a VM. Do note that your business logic DLL should not have references to any libraries which will only run in Cloud Services kind of environment (e.g. Diagnostics, ServiceRuntime etc.)
Do take a look at Startup Tasks for Cloud Services. They do provide a mechanism to perform additional tasks like installing software when your Cloud Service is deployed.

Is Azure Worker Role for an on-premise solution available through Windows Azure Pack or App Fabric

I am writing an application that will be deployed both to the cloud and to on-premise data-centres (for those clients who, essentially, don't yet trust the cloud with their data.
If i choose to go MS Azure I can use the new cloud project types with their Web and Worker roles. But how can I get the worker roles running for the on-premise variant?
Do I have to write my own host (say as a windows service)? This is not ideal as it requires additional code and deployment.
Is there an Azure compatible approach, say in the Windows Azure Pack or the App Fabric stuff (is App Fabric still current?) that doesn't require the full setup of the private cloud ?
This doesn't exist in Azure Pack.
There is no need to try and have a Worker Role on premise. All you need to do is to have a Virtual Machine that you install a Windows Service on.
It's easy to create a Windows Service using Topshelf.
Deployment of a Windows Service with Topshelf is actually much easier than deployments for Worker Roles because you just run the .exe you create with the install and then with the start arguments.
Because of this you actually need less code than for a Worker Role since you don't need a second wrapper project.
While I haven't used Windows Azure Pack before it does seem capable of providing this functionality in house, however the requirements and setup procedures are intense and it is certainly geared towards enterprise.
A better option is for you to create a console app that triggers the OnStart() and Run() functions for your WorkerRole based on your OS Task Scheduler.
Not too much work in my opinion and you get to keep your WorkerRoles as is but just add the console app for any on premise solutions.

Is it possible to use Azure diagnostics without being in a hosted service

I have several web and worker roles in my solution, but I also have a non-Azure application running on a Azure hosted VM. That application connects to Azure storage for various things like reading and writing blobs and queues, and that works fine.
I'd like to use Azure diagnostics from within that same application (a .NET app running on a VM hosted in Azure). However, if I try to initialize diagnostics I get an exception that:
System.InvalidOperationException: Not running in a hosted service or the Development Fabric.
This makes sense, but I'm wondering if it's possible to use the diagnostics in some way without being a hosted service. In particular, I'm using azure diagnostics to gather logging information, written out by System.Diagnostics.Trace, and that's all hidden away from the application code, so if there were some other APIs I have a place I can probably slot that in.
Any ideas?
Thanks,
JC
Unfortunately, no. At least not today. The agent has some hard-coded checks for the RoleEnvironment stuff and when it is not there, it fails. This is also the reason you cannot use the agent in the IaaS stuff today either.

Resources