0

这是一个与辅助角色托管 VM 有关的问题。我有一个简单的工人角色,它跨越了它内部的一个进程。产生的进程是 32 位编译的 TCPServer 应用程序。Worker 角色中定义了一个端点,TCPserver 绑定到 Worker 角色的端点。因此,当我连接到我的工作角色端点并发送一些东西时,TCPserver 会接收它,处理它会返回一些东西。所以这里暴露给外界的worker角色的端点,在内部连接到TCPserver。

string port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[""TCPsocket].IPEndpoint.Port.ToString();

            var myProcess = new Process()
            {
                StartInfo = new ProcessStartInfo(Path.Combine(localstorage.RootPath, "TCPServer.exe"))
                {
                    CreateNoWindow = true,
                    UseShellExecute = true,
                    WorkingDirectory = localstorage.RootPath,
                    Arguments = port
                }
            };

它工作正常。但突然塞弗停下来回应。当我签入门户时,VM 角色会自动重新启动。但它从未成功。它正在显示Role Initializing..状态。手动停止和启动也不起作用。我重新部署了相同的包,没有对代码进行任何更改。这次部署本身失败了。

Warning: All role instances have stopped - There was no endpoint listening at https://management.core.windows.net/<SubscriptionID>/services/hostedservices/TCPServer/deploymentslots/Production that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

但过了一段时间我再次尝试部署,它工作正常。谁能告诉我会有什么问题?

更新:

  public override void Run()
    {
        Trace.WriteLine("RasterWorker entry point called", "Information");
        string configVal = RoleEnvironment.GetConfigurationSettingValue("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString");
        CloudStorageAccount _storageAccount = null;
        _storageAccount = CloudStorageAccount.Parse(configVal); // accepts storage cridentials and create storage account
        var localstorage = RoleEnvironment.GetLocalResource("MyLocalStorage");
        CloudBlobClient _blobClient = _storageAccount.CreateCloudBlobClient();
        bool flag = false;

        while (true)
        {
            Thread.Sleep(30000);
            if (!flag)
            {
                if (File.Exists(Path.Combine(localstorage.RootPath, "test.ppm")))
                {
                    CloudBlobContainer _blobContainer = _blobClient.GetContainerReference("reports");
                    CloudBlob _blob = _blobContainer.GetBlobReference("test.ppm");
                    _blob.UploadFile(Path.Combine(localstorage.RootPath, "test.ppm"));
                    Trace.WriteLine("Copy to blob done!!!!!!!", "Information");
                    flag = true;
                }
                else
                {
                    Trace.WriteLine("Copy Failed-> File doesnt exist!!!!!!!", "Information");
                }
            }
            Trace.WriteLine("Working", "Information");
        }
    }
4

1 回答 1

1

为了防止您的工作角色重新启动,您需要阻止入口点类的Run方法。

如果您确实重写了 Run 方法,您的代码应该无限期地阻塞。如果 Run 方法返回,则通过引发 Stopping 事件并调用 OnStop 方法自动回收角色,以便可以在角色脱机之前执行关闭序列。

http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.serviceruntime.roleentrypoint.run.aspx

你需要确保,无论发生什么,如果你想保持角色活着,你永远不会从Run方法返回。

现在,如果您在控制台应用程序中托管 TCPServer(我假设您正在这样做,因为您粘贴了 Process.Start 代码),您需要在启动进程后阻止Run方法。

public override void Run()
{
   try
   {
      Trace.WriteLine("WorkerRole entrypoint called", "Information");

      var myProcess = new Process()
        {
            StartInfo = new ProcessStartInfo(Path.Combine(localstorage.RootPath, "TCPServer.exe"))
            {
                CreateNoWindow = true,
                UseShellExecute = true,
                WorkingDirectory = localstorage.RootPath,
                Arguments = port
            }
        };
        myProcess.Start();

      while (true)
      {
         Thread.Sleep(10000);
         Trace.WriteLine("Working", "Information");
      }
      // Add code here that runs in the role instance
   }
   catch (Exception e)
   {
      Trace.WriteLine("Exception during Run: " + e.ToString());
      // Take other action as needed.
   }
}

PS:这与您的部署问题无关,我认为这是一个巧合

于 2012-06-14T09:13:26.567 回答