简体   繁体   English

从启动脚本调用的C#程序访问Azure服务配置

[英]Access Azure Service config from C# program called by a startup script

I have a C# console app called during the startup of a WebRole to perform customized instrumentation. 我在WebRole启动期间调用了一个C#控制台应用程序来执行自定义检测。 I'd like for this program to be able to read the latest values from Service Config and act accordingly. 我希望该程序能够从Service Config中读取最新值并采取相应措施。

I've setup the startup script that calls my .EXE to run in elevated mode. 我已经设置了调用我的.EXE的启动脚本,以在提升模式下运行。 I've added a reference to Azure's ServiceRuntime to the console app, however I'm getting the following error: role discovery data is unavailable 我已在控制台应用程序中添加了对Azure的ServiceRuntime的引用,但是出现以下错误: 角色发现数据不可用

If you've put calling this executable as a start-up task in the .csdef, then the information you're asking for may not be available as the role has not yet been set up (see lifecycle of Web/Worker role ). 如果您已在.csdef中将调用此可执行文件作为启动任务,则由于尚未设置角色,因此可能无法获得您要求的信息(请参阅Web / Worker角色的生命周期 )。

This could also be the problem if you're calling the executable within OnStart in WebRole.cs - as IISConfigurator is called asynchronously with OnStart. 如果要在WebRole.cs的OnStart中调用可执行文件,这也可能是问题-因为IISConfigurator与OnStart异步调用。

For the startup task, one work around for this is detailed at http://mvolo.com/configure-iis-websites-windows-azure-startup-tasks-appcmd/ (although it deals with changing IIS configuration). 对于启动任务, http://mvolo.com/configure-iis-websites-windows-azure-startup-tasks-appcmd/中详细介绍了解决此问题的方法(尽管它涉及更改IIS配置)。

For the WebRole issue, you could overload Run() and call your executable from there - possibly with retries like: 对于WebRole问题,您可以重载Run()并从那里调用可执行文件-可能需要重试,例如:

 while (!RoleEnvironment.IsAvailable) {
     Thread.Sleep(1000);
 }
 RunExecutable();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM