在Node.js上收到“更改”+“更改”事件后,Azure Workerangular色重新启动

我使用azure-sdk-for-node包在Azure工作者angular色中运行一个简单的Node.js应用程序。

var azure = require('azure'), http = require('http'), winston = require('winston'), logger = new (winston.Logger)({ transports: [ new (winston.transports.File)({ filename: 'C:\\log.txt' }) ] }), http.createServer(function (req, res) { res.writeHead(200); res.end('Hello, World!'); }).listen(process.env.port || 1337); azure.RoleEnvironment.on('changing', function (changes) { winston.info('changing', changes); // Got configuration changes here // { // "changes": [ // { // "type": "ConfigurationSettingChange", // "name": "MyApp.Settings1" // }, // { // "type": "ConfigurationSettingChange", // "name": "Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" // } // ] // } }); azure.RoleEnvironment.on('changed', function () { // Also got this event winston.info('changing'); }); azure.RoleEnvironment.on('stopping', function () { // Never fired winston.info('stopping'); }); 

应用程序在工作angular色上运行良好,没有问题,直到我通过pipe理门户修改configuration。

我通过pipe理门户更新了configuration,并单击保存。 不久之后,我又在应用程序中changingchanged事件。 但在接收这些事件6分钟后,整个工作者angular色重新启动,没有任何stopping事件。 我使用winston软件包login到C:\,并通过重新启动将日志保留。

日志显示如下:

 00:00 setup_worker.cmd 00:01 server.js with PID 1 00:06 "role changing" 00:06 "role changed" 00:12 setup_worker.cmd 00:13 server.js with PID 2 

(注意:setup_worker.cmd是CSDEF中的启动脚本,server.js是我的应用程序)

尽pipeconfiguration更改后没有stopping事件,但是如果通过Management Portal手动重新引导实例,则会收到stopping事件。

所以有几个问题:

  1. configuration更改后为什么重新启动angular色?
  2. 如何防止configuration更改后重新启动angular色?
  3. 为什么在通过configuration更改重新启动angular色时没有stopping事件?

谢谢!

  1. Azure假定您希望在更改configuration后重新启动服务器,以便新设置可以正常生效。 它不知道您是否在运行时或只在启动时继续阅读您的configuration设置。 它还假定你的angular色部署了2台服务器,并且一次重新启动它们不会损害你的网站

  2. 所以,我不熟悉node.js,但是,在.NET中,我们可以监视RoleEnvironment.Changing事件,将其捕获并忽略重新启动。 检查这篇文章: http : //msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.changing.aspx你可以做一些类似的function委托之后,你陷阱的变化事件?

  3. 我相信停止事件只适用于closuresangular色/停止angular色。 http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.stopping.aspx