It was Sunday 09:45, the birds were cheerping and the sky was blue, when suddenly this peace was interrupted by the ring of my phone. That’s right, I was on stand-by duty that week and my consumer just called to inform me that the production environment of Citrix is down.
After some question I determined there, indeed, is something wrong so I started my laptop, logged on to the environment and started troubleshooting. Hmmm, no icons on Storefront? That must be the database.
Once headed to the database server, which is on Server Core, I fired the command Get-Service -Name MSSQLSERVER which showed me the service was not running. That’s weird, because the start-up type of the service was on Automatic. I started the service and the issue seemed to be solved. I realized the servers were automatically patched on Sunday, could this be related to a reboot?
I decided to perform a system info to determine the boot time of the server, and this confirmed the server has suffered from a reboot.
So, to prevent this from happening again I need something to make sure SQL is getting started when it’s down, so I can enjoy my well-deserved sleep
I went ahead and started programming some PowerShell after which I converted my script to an executable. The script works with the input of a JSON file, which is easy to read. This JSON file needs to be installed in “$env:ProgramFiles\TimTools\ServiceWatcher\ServiceWatcher.json” / “%programfiles%\TimTools\ServiceWatcher\ServiceWatcher.json. You are free to choose where you will place the executable file, but the most logical place to me is to store it in the same folder:
Once satisfied with the location you can than install the service with the following command:
Of course, you can also uninstall the service with ease:
Or when you lost the executable:
sc.exe delete ServiceWatcher
Let’s put it to the test, in the example below we’re testing with Citrix components, but of course you can specify each service you like and you can even use wildcards like in the example below:
The application has only been tested on Windows 10 21H1 and Windows Server 2019 but should theoretically also work on Windows 7, Windows 8/8.1, Server 2008, Server 2012 and Server 2016. However, I do not recommend the use of deprecated operating systems. More information about Windows lifecycles can be found on https://docs.microsoft.com/en-us/lifecycle/products/
So, after implementation I think it’s fair to say I nailed it and now I can go back to sleep.
If you’ve encountered a bug/question/feature request, feel free to contact me on LinkedIn.
The application can be found on GitHub.
Author: Tim Nissen