Azure VM意外重启

时间:2012-06-14 09:05:14

标签: azure azure-worker-roles azure-vm-role

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

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");
        }
    }

1 个答案:

答案 0 :(得分:1)

要防止重新启动工作人员角色,您需要阻止入口点类的运行方法。

  

如果覆盖Run方法,则代码应该阻止   无限期。如果Run方法返回,角色将自动回收,方法是引发Stopping事件并调用OnStop方法   这样你的关机序列可以在角色之前执行   离线。<​​/ p>

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

您需要确保无论发生什么情况,如果您想让角色保持活跃状态​​,您永远不会从运行方法返回。

现在,如果您在控制台应用程序中托管TCPServer(我假设您在粘贴Process.Start代码后正在执行此操作),则需要阻止运行启动过程后的方法。

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:这与您的部署问题无关,我认为这是巧合