Controlling start up sequence of a windows service
Asked Answered
B

4

5

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.

Bedding answered 14/1, 2009 at 2:34 Comment(0)
M
5

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

Mesozoic answered 14/1, 2009 at 2:47 Comment(4)
Thank you. That worked great. I added the installer class - went to properties and added a dependency to "MSSQLSERVER" service. Seems to work. Wonder if the service name is going stay the same for SQL server 2005, 2008..Bedding
What happens if the user wants to run SQL Server on a centralized failover cluster, or just another box?Ralfston
@matthamilton the top link is brokenMaxillary
@DuncanGroenewald The perils of the web. Sadly URLs aren't guaranteed to be permanent when they're just blog posts. :( Fixed now.Mesozoic
T
2

You can set dependencies between the services.

See here:

Thach answered 14/1, 2009 at 2:45 Comment(0)
D
2

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

Danialah answered 11/5, 2010 at 15:57 Comment(0)
R
2

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.

Ralfston answered 18/10, 2010 at 17:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.