应用程序超时时如何重新启动Coldfusion Application Server?

发布于 2024-10-17 23:05:14 字数 680 浏览 3 评论 0原文

当应用程序超时时,有没有办法通过Application.cfc重新启动CF服务器?根据 Adob​​e 文档,它们显示如下:

<cffunction name="onApplicationEnd">
    <cfargument name="ApplicationScope" required=true/>
    <cflog file="#This.Name#" type="Information" 
        text="Application #Arguments.ApplicationScope.applicationname# Ended" >
</cffunction>

我想做的是将上面的 替换为 ,如下所示:

<cfexecute name = "C:\CFRestart.bat"
    outputFile = "C:\output.txt"
    timeout = "1">
</cfexecute>

所以 OnApplicationEnd 将在应用程序超时时运行 CFRestart.bat 文件。这可能吗?

Is there any way to restart the CF server through the Application.cfc, when the application times out? As per Adobe documentation, they showed as follows:

<cffunction name="onApplicationEnd">
    <cfargument name="ApplicationScope" required=true/>
    <cflog file="#This.Name#" type="Information" 
        text="Application #Arguments.ApplicationScope.applicationname# Ended" >
</cffunction>

What I would like to do is replace the <cflog> above with <cfexecute> as follows:

<cfexecute name = "C:\CFRestart.bat"
    outputFile = "C:\output.txt"
    timeout = "1">
</cfexecute>

So OnApplicationEnd will run the CFRestart.bat file when the application times out. Is this possible or not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

心的憧憬 2024-10-24 23:05:14

onApplicationEnd 不太可能除非您有一个非常安静的应用程序,否则会达到,因为每次有人访问该应用程序时,超时都会重置。

使用应用程序重新启动 Coldfusion 实例我会感到非常不舒服。我可以看到各种可怕的安全问题等迫在眉睫。老实说,我不太确定如果应用程序结束,为什么要重新启动服务器。

另外,根据文档, onApplicationEnd 在服务器重新启动时被调用,因此,如果您确实做到了这一点,那么当您重新启动服务器时,应用程序也会尝试重新启动服务器。这会变得非常混乱。

onApplicationEnd is not likely to be reached unless you have a very quiet application because every time someone access the application the timeout is reset.

I'd be very uncomfortable using an application to restart a coldfusion instance. I can see all sorts of horrible security issues etc looming. To be honest I'm not really sure why you'd want to restart the server if your application end.

Also, according to the docs onApplicationEnd is called when the server is restarted, so if you did get this working, when you restart your server the application would also have a go at restarting your server. This would get very messy.

余厌 2024-10-24 23:05:14

不相信您可以从 ColdFusion 调用 .bat 脚本。因为一旦停止服务, 也将终止(认为它在 CF 服务下运行),永远不会重新启动。

猜测您的服务器经常因为遇到内存不足 (OOM) 异常而发生故障。为了克服这些情况下的困难,我将批处理脚本设置为 Windows Scheduled定期(例如每 24、12 或 6 小时)重新启动服务器的任务(参见第一个答案以了解如何执行)。选择适合您情况的间隔。

假设 OOM 是根本原因,我建议下载 Java JDK,配置 ColdFusion 来使用它(即 jvm.config 文件中的 jvmhome),并传递参数以启用 JMX 连接。 您使用此 JMX 连接来监视 ColdFusion Visual VM,它是JDK自带的。从那里您可以生成堆转储文件和/或告诉虚拟机在 OOM 时生成一个堆转储文件。 Tehn 我已经通过 Eclipse 内存分析器工具 成功运行了该工具,该工具疑似存在泄漏报告不止一次帮助追踪服务器 OOM 崩溃的根本原因。

如果这不是您的情况,那么我建议您在使用 ColdFusion enterprise 时启用快照,否则 cfstat 是您标准的朋友。对于任一情况,您还可以设置发送通知的探测器 当服务器运行缓慢时。这可以帮助您连接到有问题的服务器并在适当的时间生成转储或确定问题是否与负载相关。

Don't believe you can call the .bat script from ColdFusion. Because once it stops the service the <cfexecute> will also terminate (think it runs under the CF service), never reaching the restart.

Guessing you have a server that routinely fails because you're hitting an Out of Memory (OOM) exception. To get over the hump in those situations I setup as batch script as a Windows Scheduled Task (see the first answer there for how) that restarts the server periodically, say every 24, 12, or 6 hours. Choose an interval that makes sense for your situation.

Assuming OOM is the root cause, I suggest downloading a Java JDK, configuring ColdFusion to use it (i.e. jvmhome in jvm.config file), and passing parameters to enable a JMX connection. You use this JMX connection to monitor ColdFusion using Visual VM, which comes with the JDK. From there you can generate a heap dump file and/or tell the VM to generate one on OOM. Tehn I've had very good success running that through the Eclipse Memory Analyzer Tool, which has a suspected leaks report that more than once has helped track down the root cause of server OOM crashes.

If that is not your scenario then I suggest enabling snapshots if you're using ColdFusion enterprise, otherwise cfstat is you friend on standard. For either one, you can also setup probes that send a notification when the server is running slowly. This can help you connect to the server in question and generate a dump at the appropriate time or identify if the problem is load related instead.

没企图 2024-10-24 23:05:14

这可能不是您的答案,但我经常使用它来帮助 JVM 内存中的垃圾收集。

将其设置为每 5 分钟运行一次的计划任务,我再也不会遇到 jvm 内存问题了。

<cfparam name="url.maxused" default="999">
<cfparam name="url.minfree" default="300">

<cfif NOT isDefined("runtime")>
    <Cfset runtime = CreateObject("java","java.lang.Runtime").getRuntime()>
</cfif>

<cfset fm = runtime.freememory()/>
<Cfset fm = int((fm/1024)/1024)/>
<cfset usedmem = 1270-fm/>
<cfoutput>
 #Now()#<br>
 Before<br>
 Free: #fm# megs<br>
 Used: #usedmem# megs<br>
</cfoutput>
<br>
<!--- check if we are using too much memory --->
<cfif usedmem gt url.maxused or fm lt url.minfree>
 <cfset runtime.gc()>
 Released Memory<br>
<cfelse>
 No need to release memory using the thresholds you provided<br>
</cfif>
<br>
<cfset fm = runtime.freememory()/>
<Cfset fm = int((fm/1024)/1024)/>
<cfset usedmem = 1270-fm/>
<cfoutput>
After<br>
Free: #fm# megs<br>
Used: #usedmem# megs<br>
</cfoutput>

This may not be your answer, but I use this often to help the garbage collection in JVM memory.

Set this as a scheduled task to run every 5 minutes, and i never get jvm memmory problems anymore.

<cfparam name="url.maxused" default="999">
<cfparam name="url.minfree" default="300">

<cfif NOT isDefined("runtime")>
    <Cfset runtime = CreateObject("java","java.lang.Runtime").getRuntime()>
</cfif>

<cfset fm = runtime.freememory()/>
<Cfset fm = int((fm/1024)/1024)/>
<cfset usedmem = 1270-fm/>
<cfoutput>
 #Now()#<br>
 Before<br>
 Free: #fm# megs<br>
 Used: #usedmem# megs<br>
</cfoutput>
<br>
<!--- check if we are using too much memory --->
<cfif usedmem gt url.maxused or fm lt url.minfree>
 <cfset runtime.gc()>
 Released Memory<br>
<cfelse>
 No need to release memory using the thresholds you provided<br>
</cfif>
<br>
<cfset fm = runtime.freememory()/>
<Cfset fm = int((fm/1024)/1024)/>
<cfset usedmem = 1270-fm/>
<cfoutput>
After<br>
Free: #fm# megs<br>
Used: #usedmem# megs<br>
</cfoutput>
逆夏时光 2024-10-24 23:05:14

这个问题已经存在了很长时间没有答案,所以我想我应该帮助解决这个问题。

首先,这个:
“服务器错误 服务器遇到内部错误,无法完成您的请求。无法连接到 JRun 服务器。”

这不是应用程序超时,这只是服务器变得无响应,或者内存不足,或者只是遇到了它不喜欢的东西。但这与应用程序超时无关。

当该网站上没有任何活动(即:没有页面请求...没有访问者)超过应用程序超时期限(默认情况下为两天(或您设置的任何时间))时,应用程序就会超时在您的 Application.cfc 中设置)。

现在...我可以理解为什么如果您的服务器变得无响应,您可能想要恢复,但是您从错误的角度来处理这个问题。本质上,如果服务器无法工作,您就无法使用该服务器执行任何操作(例如治愈本身)!这里通常做的是一些其他进程检查服务器是否响应,如果该服务确定服务器没有响应,则发出重新启动。

因此,您应该查看其他一些可以向您的 CF 服务器执行 HTTP 请求的软件,如果对 HTTP 请求的反应表明 CF 服务器没有响应,则监控软件会告诉 CF 重新启动。

This has been hanging around unanswered for an age, so I thought I'd help getting it cleared up.

First, this:
"Server Error The server encountered an internal error and was unable to complete your request. Could not connect to JRun Server."

This is NOT an application timeout, this is just the server becoming unresponsive, or running out of memory, or just encountering something it doesn't like. But it's nothing to do with the application timing out.

The application times out when there's been no activity (ie: no page requests... no visitors) on that site for longer than the application timeout period, which by default is two days (or whatever you have set in your Application.cfc).

Now... I can understand why you might want to recover if your server becomes unresponsive, bur you're approaching this from the wrong angle. Intrinsically if the server ain't working, you can't use that server to do anything (like cure itself)! What is generally done here is that some other process checks that the server is responsive, and if that service determines the server is not responsive, issues a restart.

So you should look at some other software which can perform an HTTP request to your CF server, and if the reaction to the HTTP request suggests the CF server is unresponsive, then the monitoring software tells CF to restart.

手心的温暖 2024-10-24 23:05:14

要添加 Stephen Moretti 的答案,这可能是您在寻找上述有趣问题的可能解决方案:

当应用程序启动时,OnApplicationEnd 是否会运行 CFRestart BAT 文件
超时?

直接的答案是否定的。由于OnApplicationEnd()事件是Application生命周期的一部分,因此当应用程序本身超时时,这里不会调用任何事件。 这一点必须明确。

不过,直接回答您的问题,是的,您可以在应用程序超时或结束时运行自定义脚本文件(无论情况如何)。您必须在此处处理服务范围

To add to the answer by Stephen Moretti and may be the possible solution you were looking for to your interesting question above:

Will the OnApplicationEnd run CFRestart BAT file when application is
timeout?

The straight answer is no. Since the OnApplicationEnd() event is a part of the Application's life cycle, so when the application itself is timed out, there is no event that will be called here. This must be clear.

Getting straight to your question though, yes, you can make a custom script file run on the event of an application timeout or end (whatever is the case). You will have to deal with the Serve Scope here.

朕就是辣么酷 2024-10-24 23:05:14

首先,应用程序不会超时,页面请求会超时。请求超时时,不会调用 onApplicationEnd() 函数。仅当应用程序关闭时才会调用该函数。以下是有关 CF 应用程序生命周期的一些信息循环。

其次,根据我的经验,无论出于何种原因重新启动应用程序服务器都可能掩盖了您的真正问题。 如果您的应用程序运行缓慢/崩溃等,那么我建议您调查发生这种情况的真正原因,而不是重新启动它。

但是,我想不出原则上这不起作用的原因,但我建议您进行快速测试,如果这确实是您想要做的。

希望有帮助。

First up, the application doesn't timeout, a page request does. On request timeout the onApplicationEnd() function is not called. That is only called if the application is shutting down. Here is some info on the CF application life cycle.

Second, in my experience, restarting application servers for whatever reason is probably masking your real problem. If you application is running slow / crashing etc. then I suggest you look into the real reason this is happening rather than restarting it.

However, I can't think of a reason this would not work in principle, but I would suggest you conduct a quick test if this really is what you wish to do.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文