Content is available under Creative Commons Attribution.


Stopping/starting windows services in parallel with Leroy

So you are some sort of smarty unix sysadmin and think that doing some simple parallel forking in bash scripts are simple in your little linuxy world… then you are faced with the fun and adventure of Windows servers and find that doing things in parallel is not so easy to do. When you have many services installed on your windows server as part of your application, you’ll find that when you automate the deployment for it, your “net start” and “net stop” commands will be painfully slow going in serial.

This is where Leroy becomes a super-helper ! Since Leroy agents have a python interpreter built into them, you gain the power and flexibility of python 3 on all platforms. With it, we can do simple things like stop and start services in parallel. Here’s an example:

For more examples and documentation on different things you can do with the execute tag please visit:

If you wanted to create a script that started services in parallel, you’d just need to change the subprocess.Popen statement to: subprocess.Popen([“net”,”start”,x]) here’s a complete example of that:

Save each of these files to: $LEROY_HOME/workflows/start-parallel-services.xml and ../workflows/stop-parallel-services.xml respectively.

Many times, windows services act somewhat wonky, and we can’t reliably tell if a service has successfully started or stopped based on ERRORLEVEL, thank goodness Leroy offers a postprocess feature for execution steps. This allows us to define a regex which can be a list of strings we do or do not want to see. More info on postprocess can be found in the tag reference:


Leave a Reply

by: Epic Force