1

I've tried a few different solutions but haven't had any that work. I am not use to batch scripting, so this has been quite trivial for me.

Right now, I have a script in Linux that handles the execution of services in synchronous order. They depend on one another and require the other one to be completely started before they can be executed.

I am using the following line to deal with this:

grep -qi 'Service has started.\|error' <(tail -f "/opt/app/log/daemon.log")

Works great. However, this also needs to work in Windows. I've looked into using the GNU utils but I haven't really looked into their licensing, which could pose a problem. Plus, I would like to do this natively in the Windows CL.

Cheers,
Chris

P.S.
I am looking for a platform INDEPENDENT solution. Cygwin is not an answer.

user0000001
  • 2,092
  • 2
  • 20
  • 48
  • In Windows, services that depend on other services can specify that and the SCM (service control manager) handles the order of startup. See this SO post for more details: http://stackoverflow.com/questions/5159257/create-dependency-between-windows-services-startup – Keith Hill Jul 15 '15 at 01:26
  • See also here http://stackoverflow.com/questions/573623/is-powershell-ready-to-replace-my-cygwin-shell-on-windows/ for some code examples about grep, tail and more. Also this sounds like you're having an XY problem with Windows services. – Vesper Jul 15 '15 at 06:33

2 Answers2

1

You should use native Windows "dependency" of services upon one another. Use regedit.exe or sc.exe config to introduce dependencies. This way, you can leave the service startup as automatic and they will only start executing once all services this one is dependent upon has reported their condition as "started".

Vesper
  • 18,599
  • 6
  • 39
  • 61
  • Is there a method to let Windows know that the service has fully initiated in JAVA. I've looked at this possible solution before posting this but found nothing that tells the SCM that the service has fully initiated. The first daemon that is launched takes a solid 60 seconds to finish it's startup. However, Windows considers the application "ready" when it actually loads but there is a lot of behind the scene stuff going on. If that makes sense. – user0000001 Jul 15 '15 at 13:50
  • You are potentially using something like JBOSS, which indeeed turns "Running" only when `java.exe` loads the class, and does not come to operation until a certain initialization passes. This makes sense, if so, you will have to control availability in your next service, if possible, or indeeed use a script that tests extended functionality of a service that reports running while not ready for actual service. I think this is a defect in the software, either in Java itself or in the loaded module that indicates its readiness before actually being ready. – Vesper Jul 15 '15 at 13:57
  • Actual tests, of course, are dependent on what your Java service should normally do, say open HTTP local port and process a status request. If failed, just delay your services in starting (probably extending time allowed for Windows to keep the service in starting - there are some stones to walk around), sleep and retry, up to a predefined timeout. – Vesper Jul 15 '15 at 14:01
0

If you're wanting to do this natively in Windows, 'the Windows way', you'll want to be using the *-Service cmdlets (e.g. Get-Service, Stop-Service, Start-Service and Restart-Service) in PowerShell.

I'll admit, I'm not a linux user, but I assume that you checking the status of a service after starting it?

On Windows, in a PowerShell script, you'd want to do something like the following (I'm specifically picking on the Volume Shadow Copy service, because reasons):

Start-Service -Name VSS

While ((Get-Service -Name VSS).Status -ne 'Running') {
    Start-Sleep -Seconds 2
}

# Start next service or continue with script here.

Apologies if this is well off base from what you're looking for. I'm just approaching this question as a Windows admin from the perspective of how I would achieve the goal.

Windos
  • 1,796
  • 1
  • 13
  • 19