如何配置网站以使用TFS版本管理自动启动? [英] How can I configure a website to start automatically using TFS release management?

查看:50
本文介绍了如何配置网站以使用TFS版本管理自动启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[我要发布此消息是为了记录经过数小时痛苦的反复试验后我实际发现的东西.]

我有一个网站,需要一直运行" (因为在这种情况下,它有一个Hangfire工作,负责每5分钟启动一次计划任务),并且默认情况下,仅在收到第一个请求时启动网站.

因此,如何确保网站自动启动?而且,如何通过TFS版本管理工具来配置它?

解决方案

[此答案并非专门针对Hangfire,但请参见

但是,启动应用程序池不会启动与其关联的一个或多个网站.在收到第一个请求之前,不会加载网站.

在IIS8(或带有扩展名的IIS7.5)中,一个

这些设置的组合可确保在IIS启动时以及应用程序池回收后立即自动启动网站.

但是,如何将这些设置作为TFS发布管道的一部分自动应用,而不需要记住手动设置?

在发布定义中,您大概有一个"IIS Web App管理"任务,该任务设置了应用程序池和网站.在此步骤的配置面板中,应该有一个带有其他AppCmd.exe命令"输入字段的高级"框.您可以使用AppCmd来应用上述设置.

AppCmd具有我在代码高尔夫竞赛之外见过的最令人困惑的命令行语法,但这是对我有用的咒语:

 设置配置/section:applicationPools-[name ='myAppPoolName'].startMode:AlwaysRunning设置应用"mySiteName/"/preloadEnabled:true 

请注意,如果您为应用程序池名称和网站名称定义了配置变量,则可以使用这些变量而不是对名称进行硬编码,例如:

 设置配置/section:applicationPools-[name ='$(appPoolName)'].startMode:AlwaysRunning 

我希望这对某人有帮助...感谢您的聆听:-)

[I'm posting this to record what I actually found out after hours of painful trial-and-error.]

I have a website that I need to be "always running" (because in this case it has a Hangfire job that's responsible for kicking off a scheduled task every 5 minutes), and by default, websites are only started up when the first request is received.

So, how can I ensure that the website is started automatically? And, how can I configure this via the TFS release management tool?

解决方案

[This answer isn't specific to Hangfire, but see the Hangfire documentation's discussion of this issue for details of how it affects Hangfire, but note that the recommended work-around is somewhat involved, and much more complex than the solution below. See also a separate and quite comprehensive discussion on the Hangfire support forum that gives several alternative solutions.]

In IIS, each website is associated with an Application Pool (App Pool). You can configure your App Pool to start automatically via IIS Manager by changing the "Start Mode" to AlwaysRunning in "Advanced Settings" for the App Pool:

However, starting the App Pool doesn't start the website (or websites) associated with it. The website does not get loaded until the first request is received.

In IIS8 (or IIS7.5 with an extension), a new setting was added that allows us to work around this. You can ensure that the website gets sent a request as soon as the App Pool starts by setting "Preload Enabled" to True in "Advanced Settings" for the website:

The combination of these settings ensure that the website will automatically start up when IIS starts, and immediately after the App Pool is recycled, etc.

But, how can you get those settings applied automatically as part of a TFS release pipeline, rather than having to remember to set them manually?

In your release definition, you presumably have an "IIS Web App Management" task, which sets up the App Pool and the website. In the configuration panel for this step, there should be an "Advanced" box with an "Additional AppCmd.exe Commands" entry field. You can use AppCmd to apply the settings described above.

AppCmd has the most confusing command-line syntax I've yet seen outside of code-golf competitions, but here's the incantation that worked for me:

set config /section:applicationPools -[name='myAppPoolName'].startMode:AlwaysRunning

set app "mySiteName/" /preloadEnabled:true

Note that if you have configuration variables defined for your App Pool name and website name, then you can use those rather than hard-coding the name, such as:

set config /section:applicationPools -[name='$(appPoolName)'].startMode:AlwaysRunning

I hope this helps somebody... Thanks for listening :-)

这篇关于如何配置网站以使用TFS版本管理自动启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆