Windows 启动时如何运行具有故障处理功能的应用程序
全部。我有一个有线保护壳 我有两个控制台.net 应用程序。 假设 app1 和 app2。
我希望这两个应用程序在 Windows 服务器启动时运行(无需登录,我的两个应用程序将自动运行),
但有一个规则,app1 必须在 app2 之前运行至少 10 分钟。 其中任何一个崩溃了,我希望它们能够自动再次升起,
有人知道我该怎么做吗???
all. i got a wired case
i got two console .net applications.
let say app1 and app2.
i want both the applications run when the windows server startup (without login, my two apps will run automatically)
but there is a rules, app1 must run at least 10 minutes before app2.
and any one of them crash, i want them can raise up again automatically
does anyone know how can i do this???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我看来,唯一可接受的方法是使用第三个服务作为看门狗,并在其他服务启动时触发。
这必须由具有定期“心跳”的其他进程提供服务,以防止它关闭和重新启动它监视的服务。
The only acceptable way in my mind is to have a third service that acts as a watchdog and triggers when the other services would start.
This will have to be serviced by the other processes with a regular "heartbeat" in order to prevent it from closing and restarting the services that it watches.
启动 app1 设置计时器。 10 分钟后启动 app2 并进入 app2_launched 状态。然后使用 pid 文件或操作系统共享对象之类的东西来相互“监视”
start app1 setup timer. after 10 minutes elapsed start app2 and go to the state app2_launched. then use something like pid files or os shared objects to 'monitor' each other
首先,如果您的应用程序必须在没有用户登录的情况下运行,那么它们必须是服务。
现在,在创建服务时,您可以决定如何响应崩溃。您可以将服务配置为在崩溃时重新启动(请参阅服务属性对话框)。
如果 App1 崩溃,是否必须停止 App2,启动 App1,然后 10 分钟后重新启动 App2?或者说,你可以立即重新启动App1吗?
然而,根据您的描述,对开始排序的控制似乎足够复杂,内置的服务配置是不够的,因此您很可能需要将该逻辑保留在某处。
如果 App1 可以了解 App2,那么您可以在 App1 中拥有该逻辑。然后,App1 将承担 2 个职责(自行运行和管理 App2 服务的状态)。
另一方面,您可以拥有第三个服务,仅负责管理 App1 和 App2 服务的生命周期和运行状况。这就是 ChrisBD 建议的看门狗。
First, if your apps must run without a user logging in, they must be services.
Now, when creating a service, you can decide how you want to respond to crashes. You can configure a service to restart in the case of a crash (see the service properties dialog).
If App1 crashes, do you have to stop App2, start App1, and then, 10 minutes later, restart App2? Or in that case, can you just restart App1 immediately?
From what you describe however, The control over start ordering appears complex enough that built in service configuration will not be sufficient, so you'll most likely need to keep that logic somewhere.
If it is ok for App1 to know about App2, you could have that logic in App1. App1 would then have 2 responsibilities (to run itself, and to manage the state of the App2 service).
On the other hand, you could have a third service that is just responsible for managing the lifecycle and health of App1 and App2 services. This is the watchdog that ChrisBD suggests.