控制Windows服务的启动顺序

发布于 2024-07-11 10:00:38 字数 265 浏览 10 评论 0原文

我使用 installutil 安装了一个 Windows 服务并将其设置为“自动启动”。 我的问题是,当某些服务器重新启动时,它会尝试在“Microsoft SQL 服务”启动之前启动 - 我可以通过在系统重新启动期间查看事件日志来看到这一点。 在 Sql 服务器服务启动后,使我的服务“自动启动”的最佳方法是什么?

我正在考虑创建一个 SQL 作业,设置为在“SQL 服务器代理”启动时启动,进而启动 Windows 服务。 但希望有一种简单、有效的方法来控制自动服务的启动顺序。

I have a windows service installed using installutil and set to "Autostart". My problem is that when some servers are rebooted it attempts to start before "Microsoft SQL service" has started- I can see this by looking at the event log during a system restart. What is the best way of making my service "auto start" AFTER Sql server service has started?

I am toying with the idea of creating a SQL job set to start when "SQL server agent" starts that in turn starts the windows service. But hopefully, there is an easy, effective way of controlling the order in which automatic services start up.

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

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

发布评论

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

评论(4

り繁华旳梦境 2024-07-18 10:00:38

每个 Windows 服务都有一个它所依赖的其他服务的列表。 这意味着它将等到其依赖项启动后才会尝试启动,如果您的依赖项启动时它们没有自动启动,它将为您启动它们。

如果您要在 .NET 中创建 Windows 服务,这里有一篇博客文章可能会有所帮助:

如何:编码服务依赖项

否则,此处有一个 Microsoft 知识库条目,详细介绍了通过注册表添加服务依赖项的方法:

如何延迟加载特定服务

Each Windows Service has a list of other services it depends on. That means it'll wait until its dependencies have started before it will attempt to start, and it'll start them for you if they weren't started automatically when yours is started.

If you're creating your Windows Service in .NET, there's a blog post here that might be helpful:

How to: Code Service Dependencies

Otherwise there's a Microsoft kb entry here that details a way to add service dependencies via the registry:

How to delay loading of specific services

溺渁∝ 2024-07-18 10:00:38

您可以设置服务之间的依赖关系。

请参阅此处:

You can set dependencies between the services.

See here:

叶落知秋 2024-07-18 10:00:38

如果您想使用批处理脚本执行此操作,则以下命令将帮助

REG ADD "HKLM\SYSTEM\CurrentControlSet\Services\%ServiceKey%" /v "DependOnService" /t REG_MULTI_SZ /d "Service Number 01\0Service Number 02"

这使用 reg.exe 看这里

If you want to do this with a batch script then the following will help

REG ADD "HKLM\SYSTEM\CurrentControlSet\Services\%ServiceKey%" /v "DependOnService" /t REG_MULTI_SZ /d "Service Number 01\0Service Number 02"

This uses reg.exe see here

_畞蕅 2024-07-18 10:00:38

依赖性很诱人,但对于 SQL Server 来说可能会对系统的长期设计有害。 考虑一下您的应用程序是否会取得成功,并且您的客户是否希望迁移到另一个机器上的单独 SQL 服务器,或者迁移到故障转移集群。

更好的设计可能是在服务启动时放置一些重试/超时逻辑,以便它会尝试联系 SQL Server(甚至可能在另一台计算机上),等​​待,尝试,然后优雅地失败。

Dependencies are tempting but in the case of SQL Server can be harmful to the longer term design of your system. Consider if your app gets to be successful and your clients want to move to a separate SQL server on another box, or to a failover cluster.

A better design might be to put some retry/timeout logic in the startup of your service, so that it'll try to contact the SQL Server (maybe even on another machine), wait, try, then fail gracefully.

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