2014-06-05 86 views

回答

3

NR_Jacob的答案啓發了我,謝謝!我發現你可以將角色的設置傳遞給批處理文件。因此,您需要添加如下設置: Cloud configuration settings 然後爲每個服務配置指定true或false。

然後在ServiceDefinition.csdef中您添加和行:

<Task commandLine="newrelic.cmd" executionContext="elevated" taskType="simple"> 
    <Environment> 
     <Variable name="DisableNewRelic"> 
      <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='DisableNewRelic']/@value" /> 
     </Variable> 
    </Environment> 
</Task> 

並在newrelic.cmd在頂部加入這些行:

IF "%DisableNewRelic%" == "true" (
    ECHO Found setting to disable New Relic, exiting... >> "%RoleRoot%\nr.log" 2>&1 
    EXIT /B 0 
) 

@NR_Jacob:您可以添加行newrelic.cmd到你的代碼庫?不要傷害在cmd中有這樣的設置;-)否則,我將不得不每次更新nuget包時對newrelic.cmd進行修改。

1

這篇文章來自Microsoft已針對此類問題的good solution。總結:

的環境變量添加到文件ServiceDefinition.csdef中像下面這樣:

<Variable name="ComputeEmulatorRunning"> 
    <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" /> 
</Variable> 

這將設置變量爲true,如果你是在模擬器中運行還是假如果不是。接下來,您將需要改變newrelic.cmd文件正是如此包住整個文件:

IF "%ComputeEmulatorRunning%" == "true" (
    REM This task is running on the compute emulator. Nothing goes here since we want nothing to happen. 
) ELSE (
    REM This task is running on the cloud. Place the entirety of the newrelic.cmd file in here. 
) 

這仍然會調用CMD文件,但會阻止它做任何事情,除了在生產。

+0

謝謝,你的回答啓發了我,看到我的答案。也許你可以將chage包含到newrelic.cmd中以發佈nuget包的新版本? – Zenuka