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.
- SvcMain
- i. SvcMasterPool1 ii. SvcMasterPool2 iii. SvcMasterPool3 ......
- i. SvcChildPool1 ii. SvcChildPool2 iii. SvcChildPool3 .....
Here are the rules: To stop a service:
- If #1 is to be stopped, everything else needs to be stopped before it.
- If anything in #2 needs to be stopped, the matching service in #3 needs to be stopped first. (SvcChildPool1 must stop before SvcMasterPool1)
- 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.