Ian1971
Ian1971

Reputation: 3696

Delay making virtual machine role available until startup tasks complete

Is it possible delay making a virtual machine role available untill startup tasks complete?

I have a few tasks I need to complete on virtual machine start before the machine can safely be added to the load balancer. Is there a way to do this?

Upvotes: 0

Views: 119

Answers (2)

Ian1971
Ian1971

Reputation: 3696

Found the solution. In the VM Role Startup windows service I can handle the RoleEnvironment.StatusCheck event. I can then call SetBusy() to tell prevent the instance being available in the load balancer.

    private void RoleEnvironmentStatusCheck(object sender, RoleInstanceStatusCheckEventArgs e)
    {
        if (this.busy)
        {
            e.SetBusy();
        }
        statusCheckWaitHandle.Set();
    }

Upvotes: 1

ThomasWeiss
ThomasWeiss

Reputation: 1302

I believe that setting the taskType attribute to simple will make the Role wait for the task completion before actually starting:

<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
   <WebRole name="WebRole1">
      <Startup>
         <Task commandLine="Startup.cmd" executionContext="limited" taskType="simple">
         </Task>
      </Startup>
   </WebRole>
</ServiceDefinition>

Upvotes: 0

Related Questions