如何使进程在远程Windows服务器上运行

时间:2021-11-28 20:54:26

I need to implement a background process that runs on a remote windows server 24/7. My development environment is C#/ASP.NET 3.5. The purpose of the process is to:

我需要实现一个24/7远程Windows服务器上运行的后台进程。我的开发环境是C#/ ASP.NET 3.5。该过程的目的是:

  • Send reminder e-mails to employees and customers at appropriate times (say 5:00PM on the day before a job is scheduled)
  • 在适当的时间向员工和客户发送提醒电子邮件(例如,在安排工作的前一天下午5:00)

  • Query and save GPS coordinates of employees when they are supposed to be out on jobs so that I can later verify that their positions were where they were supposed to be.
  • 当员工应该在工作岗位上时,查询并保存员工的GPS坐标,这样我以后就可以确认他们的位置是他们应该在的位置。

If the process fails (which it probably will, especially when updates are added), I need for it to be restarted immediately (or within just a few minutes) as I would have very serious problems if this process failed to send a notification, log a GPS coordinate, or any of the other tasks its meant to perform.

如果进程失败(它可能会失败,特别是在添加更新时),我需要立即(或在几分钟内)重新启动它,因为如果此进程无法发送通知,我会遇到非常严重的问题,日志GPS坐标,或其意图执行的任何其他任务。

6 个解决方案

#1


  1. Implement your process as a Windows service. For a straightforward example of how to code a Windows service this in .Net see http://www.developer.com/net/csharp/article.php/2173801 .

    将您的流程实现为Windows服务。有关如何在.Net中编写Windows服务代码的简单示例,请参阅http://www.developer.com/net/csharp/article.php/2173801。

  2. To control what happens should the service fail configure this through the "Recovery" tab on your service in services.msc. (see image below)

    要控制服务失败的情况,请通过services.msc中服务的“恢复”选项卡进行配置。 (见下图)

  3. For higly critical operation you might look into setting up a server cluster for mitigating single server failure (see http://msdn.microsoft.com/en-us/library/ms952401.aspx ).

    对于高度关键的操作,您可能会考虑设置服务器群集以减轻单个服务器故障(请参阅http://msdn.microsoft.com/en-us/library/ms952401.aspx)。

如何使进程在远程Windows服务器上运行

#2


You need a Windows Service. You can do non-visual iterative operations in windows services.

您需要Windows服务。您可以在Windows服务中执行非可视迭代操作。

#3


Another alternative is to create a normal application and run it on a schedule. Your application is run at certain times a day to perform its actions, depending on how often you need to log GPS coordinates and send reports. If your service doesn't need to run constantly this is usually the recommended approach, as services are supposed to be limited to always-on applications.

另一种方法是创建一个普通的应用程序并按计划运行它。您的应用程序每天运行一次以执行其操作,具体取决于您记录GPS坐标和发送报告的频率。如果您的服务不需要经常运行,这通常是推荐的方法,因为服务应该仅限于永远在线的应用程序。

#4


As well as being a service, you might want to run on a cluster, and make your service known to the cluster management software.

除了作为服务之外,您可能还希望在群集上运行,并使群集管理软件知道您的服务。

#5


You can create Windows Service (server programming on Windows) or use scheduler to periodically execute a task.

您可以创建Windows服务(Windows上的服务器编程)或使用调度程序定期执行任务。

Depending on the requirements for the high availability, program can be installed on a fail-over cluster where there will be other server (passive node) started and quietly waiting as a hot-backup if the first (active node) dies. This is wide topic. Start with High availablity on Wikipedia.

根据高可用性的要求,程序可以安装在故障转移群集上,其中将启动其他服务器(被动节点),如果第一个(活动节点)死亡,则静默等待作为热备份。这是一个广泛的话题。从*上的高可用性开始。

#6


In my experience if you need to run something 24x7 you need to have (one or more) watchdog process to verify that your service(s) are running correctly. Just relying on the normal service framework cannot guarantee that the program is working correctly - even if it looks like it is running. The watchdog program (which also is a service) can query the service automatically e.g. posting messages checking response times, querying for statistics and so on - when it detects problems it can restart the service (or do some other fail-recovery)

根据我的经验,如果您需要24x7全天候运行,您需要(一个或多个)监视程序来验证您的服务是否正常运行。仅依靠正常的服务框架无法保证程序正常运行 - 即使它看起来正在运行。看门狗程序(也是一种服务)可以自动查询服务,例如发布消息检查响应时间,查询统计信息等 - 当它检测到问题时,它可以重新启动服务(或执行其他一些故障恢复)

The reason for having a watchdog program as opposed to just rely on user queries to detect errors is that it can be done automatically. This is the preferred method because it allows for a proactive detection.

拥有监视程序而不是仅依靠用户查询来检测错误的原因是它可以自动完成。这是首选方法,因为它允许主动检测。

#1


  1. Implement your process as a Windows service. For a straightforward example of how to code a Windows service this in .Net see http://www.developer.com/net/csharp/article.php/2173801 .

    将您的流程实现为Windows服务。有关如何在.Net中编写Windows服务代码的简单示例,请参阅http://www.developer.com/net/csharp/article.php/2173801。

  2. To control what happens should the service fail configure this through the "Recovery" tab on your service in services.msc. (see image below)

    要控制服务失败的情况,请通过services.msc中服务的“恢复”选项卡进行配置。 (见下图)

  3. For higly critical operation you might look into setting up a server cluster for mitigating single server failure (see http://msdn.microsoft.com/en-us/library/ms952401.aspx ).

    对于高度关键的操作,您可能会考虑设置服务器群集以减轻单个服务器故障(请参阅http://msdn.microsoft.com/en-us/library/ms952401.aspx)。

如何使进程在远程Windows服务器上运行

#2


You need a Windows Service. You can do non-visual iterative operations in windows services.

您需要Windows服务。您可以在Windows服务中执行非可视迭代操作。

#3


Another alternative is to create a normal application and run it on a schedule. Your application is run at certain times a day to perform its actions, depending on how often you need to log GPS coordinates and send reports. If your service doesn't need to run constantly this is usually the recommended approach, as services are supposed to be limited to always-on applications.

另一种方法是创建一个普通的应用程序并按计划运行它。您的应用程序每天运行一次以执行其操作,具体取决于您记录GPS坐标和发送报告的频率。如果您的服务不需要经常运行,这通常是推荐的方法,因为服务应该仅限于永远在线的应用程序。

#4


As well as being a service, you might want to run on a cluster, and make your service known to the cluster management software.

除了作为服务之外,您可能还希望在群集上运行,并使群集管理软件知道您的服务。

#5


You can create Windows Service (server programming on Windows) or use scheduler to periodically execute a task.

您可以创建Windows服务(Windows上的服务器编程)或使用调度程序定期执行任务。

Depending on the requirements for the high availability, program can be installed on a fail-over cluster where there will be other server (passive node) started and quietly waiting as a hot-backup if the first (active node) dies. This is wide topic. Start with High availablity on Wikipedia.

根据高可用性的要求,程序可以安装在故障转移群集上,其中将启动其他服务器(被动节点),如果第一个(活动节点)死亡,则静默等待作为热备份。这是一个广泛的话题。从*上的高可用性开始。

#6


In my experience if you need to run something 24x7 you need to have (one or more) watchdog process to verify that your service(s) are running correctly. Just relying on the normal service framework cannot guarantee that the program is working correctly - even if it looks like it is running. The watchdog program (which also is a service) can query the service automatically e.g. posting messages checking response times, querying for statistics and so on - when it detects problems it can restart the service (or do some other fail-recovery)

根据我的经验,如果您需要24x7全天候运行,您需要(一个或多个)监视程序来验证您的服务是否正常运行。仅依靠正常的服务框架无法保证程序正常运行 - 即使它看起来正在运行。看门狗程序(也是一种服务)可以自动查询服务,例如发布消息检查响应时间,查询统计信息等 - 当它检测到问题时,它可以重新启动服务(或执行其他一些故障恢复)

The reason for having a watchdog program as opposed to just rely on user queries to detect errors is that it can be done automatically. This is the preferred method because it allows for a proactive detection.

拥有监视程序而不是仅依靠用户查询来检测错误的原因是它可以自动完成。这是首选方法,因为它允许主动检测。