1

I am writing a service that basically is responsible for turning on and off other services but they need to be turned on and off in a particular order.

  1. SvcMain
  2. i. SvcMasterPool1 ii. SvcMasterPool2 iii. SvcMasterPool3 ......
  3. i. SvcChildPool1 ii. SvcChildPool2 iii. SvcChildPool3 .....

Here are the rules: To stop a service:

  1. If #1 is to be stopped, everything else needs to be stopped before it.
  2. If anything in #2 needs to be stopped, the matching service in #3 needs to be stopped first. (SvcChildPool1 must stop before SvcMasterPool1)
  3. Services in #3 can be stopped without any pre-conditions.

To start a service: Its the exact opposite of the stopping sequence. 1. For the services in #3 to start, the matching svc in #2 and the #1 need to be started 2. Services in #2 need #1 to be started 3. No pre-conditions for #1


The number of Master and Child Svcs can increase or decrease over time. I don't want to hard code the logic in my code and i was thinking about driving it using regular expressions. What I am stumped on is getting the matching svc from #3. If i know that i need to stop "SvcMasterPool2" how do i come up with "SvcChildPool2". I can have a regex to match all the SvcChildPoolX but cannot come up with a solution to match the equivalent child.

Any help would be appreciated or any other suggestions for a more suitable approach is welcome.

I am planning on using a database but I dont want to add the sequence for individual servers. hence the idea of using RegEx. so i just store the pattern and use it across all servers.

Thanks.

mithun_daa
  • 4,334
  • 5
  • 38
  • 50

2 Answers2

0

I would create a class something like this:

public class ServiceDependencies
{
    public string ServiceName {get;set;}
    public List<ServiceDependencies> DependsOn {get;private set;}
}

And make this class serializable to xml. So you have a xml file that you can easily edit with notepad and that can also easily read in by your application.

Oliver
  • 43,366
  • 8
  • 94
  • 151
  • This service is going to be hosted on hundreds of servers so maintaining individual xml files is not going to be practical. I was planning on using a database but I dont want to add the sequence for individual servers. hence the idea of using RegEx. – mithun_daa Feb 24 '12 at 15:55
0

If the services are setup properly in Windows, then they can report what depends on them.

You can use the ServiceController to start and stop the services, and use its property DependentServices to handle starting and stopping what depends on them.

Related question: Restart a service with dependent services?

Community
  • 1
  • 1
davisoa
  • 5,407
  • 1
  • 28
  • 34