Question

I have to start two socket.io processes in my azure worker role. I followed the steps in this link Below is my ServiceDefinition.csdef

<WorkerRole name="WorkerRole1">
<Startup>
  <Task commandLine="setup_worker.cmd &gt; log.txt" executionContext="elevated">
    <Environment>
      <Variable name="EMULATED" value="false"/>           

      <Variable name="RUNTIMEID" value="node" />
      <Variable name="RUNTIMEURL" value="http://az413943.vo.msecnd.net/node/0.6.20.exe" />
    </Environment>
  </Task>      
</Startup>
<Endpoints>
  <InputEndpoint name="HttpIn" protocol="tcp" port="80" />
</Endpoints>
<Runtime>
  <Environment>
    <Variable name="PORT">
      <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='HttpIn']/@port" />
    </Variable>
    <Variable name="EMULATED">
      <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
    </Variable>
  </Environment>
  <EntryPoint>
    <ProgramEntryPoint commandLine="node.cmd .\server.js" setReadyOnProcessStart="false" />
  </EntryPoint>
</Runtime>
<Imports>
  <Import moduleName="RemoteAccess" />
  <Import moduleName="RemoteForwarder" />
  <Import moduleName="Diagnostics" />
</Imports>   
<LocalResources>
  <LocalStorage name="WorkerLocalStorage" cleanOnRoleRecycle="false" sizeInMB="1024" />
</LocalResources>

In this I am starting server.js on runtime, but I would also like to start another socket.io script along with it. The reason being I dont want to use another worker role for a small application. Just to save cost. I tried to start it as a start up task but the worker role was hanging/cycling when i started the cloud service in emulator with no error info in the output dialog box. So am guessing the socket.io scripts can only be started in the runtime section. Is there any way I can start both my socket.io scripts in a single worker role?

Was it helpful?

Solution

You can do this multiple ways:

  1. Start the process via a startup task
  2. Start the process from the role entry point.

For #1, if you were seeing the role hanging/cycling then it is because of a bug in your startup task, not because Azure prevents you from running a socket.io script. See http://blogs.msdn.com/b/kwill/archive/2013/08/09/windows-azure-paas-compute-diagnostics-data.aspx for how to troubleshoot this issue, in particular the Troubleshooting Scenario 2 (http://blogs.msdn.com/b/kwill/archive/2013/08/26/troubleshooting-scenario-2-role-recycling-after-running-fine-for-2-weeks.aspx). Also, make sure you set the startup task as background so that the host bootstrapper is not waiting for the process to exit before continuing with the role startup process.

For #2, you would have to either modify node.cmd to spawn two processes, or switch to use a different role entry point and have that role entry point start the node.cmd along with your other script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top