【发布时间】:2014-09-08 03:19:57
【问题描述】:
我在 Azure Worker Role 中运行一个简单的 Node.js 应用,带有 azure-sdk-for-node 包。
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');
});
应用程序在 Worker Role 上运行良好,没有问题,直到我通过管理门户修改配置。
我通过管理门户更新了配置并单击了保存。不久之后,我在应用程序上同时收到了 changing 和 changed 事件。但是在收到这些事件 6 分钟后,整个 Worker Role 重新启动,没有任何 stopping 事件。我使用包 winston 登录到 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是我的app)
虽然配置更改后没有stopping 事件,但如果我通过管理门户手动重启实例,我得到了stopping 事件。
所以有几个问题:
- 为什么角色在配置更改后会重新启动?
- 如何防止角色在配置更改后重新启动?
- 当角色因配置更改而重新启动时,为什么没有
stopping事件?
谢谢!
【问题讨论】: