vCenter Server 6.0 Services (Windows Edition) – One Service to rule them all!
After upgrading to vCenter Server 6.0 we all noticed the multiplying number of services that have to start, before the vCenter Server 6.0 high availability guide was released I was working on something similar in my lab but with a self-consistent vCenter Server without a shared RDM.
Anyway, in my attempts to cluster the services I noticed that the dependencies are a bit disoriented in a way for MCS to be able to start and stop them logically which eventually leads to exerting more time for the clustered resources to be transferred to the second node mainly when starting of all services it requires around 13 minutes for all the services to start and the web-client to initialize
So, I decided to write my own service to control all of the other services, now from my experience I know that in C:\Program Files\VMware\vCenter Server\bin\ there is a nifty utility called service-control which also comes as a batch file service-control.bat this utility has a lot of arguments but I am interested in two of them only –start and –stop –all the first starts all services including core and the rest of the non-core services get started via the existing dependencies and the second one stops all services including core and non-core.
I tried to use the batch file directly within the cluster resources but it just wouldn’t trigger properly which made me jump into my development mindset.
So, I downloaded Visual Studio 2013 Update 4 Community Edition and Googled a lot about creating Windows Services and spent around 3 nights tuning the service.
The service utilizes the utility mentioned above and it does the following:
- On start -> service-control.bat –start & write/append to a log file [C:\vCenterHAServiceStatus-date.txt]
- Takes around 7 minutes for all the services to start and the web-client to initialize.
- On stop -> service-control.bat –stop –all & write/append to a log file [[C:\vCenterHAServiceStatus-date.txt]
- Take around 5 minutes for all services to stop.
The service is not complex, so as long it was able to run the utility it will tell you that it has started and then you have to monitor the services and the text log file to see if anything wrong has happened.
Service Installation:
- Start -> run -> cmd
- cd C:\Windows\Microsoft.Net\Framework\v4.0.30319
- InstallUtil.exe /i C:\vCenterHAService\vCenterHAService.exe
Service Code (You can download the full project HERE):
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Linq; using System.ServiceProcess; using System.Text; using System.Threading.Tasks; using System.IO; namespace vCenterHAService { public partial class vCenterHAService : ServiceBase { public vCenterHAService() { this.ServiceName = "vCenter Server HA Service"; this.EventLog.Source = "vCenter Server HA Service"; this.EventLog.Log = "Application"; this.CanHandlePowerEvent = true; this.CanHandleSessionChangeEvent = true; this.CanPauseAndContinue = true; this.CanShutdown = true; this.CanStop = true; if (!EventLog.SourceExists("vCenter Server HA Service")) EventLog.CreateEventSource("vCenter Server HA Service", "Application"); InitializeComponent(); } protected override void OnStart(string[] args) { base.OnStart(args); String commandstart = @"service-control.bat --start >> C:\\vCenterHAServiceStatus-%date:~4,2%%date:~7,2%%date:~10,4%.txt"; var StartServiceControl = new ProcessStartInfo("cmd.exe", "/c" + commandstart) { CreateNoWindow = true, UseShellExecute = false, WorkingDirectory = "C:\\Program Files\\VMware\\vCenter Server\\bin", }; var launcdoitstart = Process.Start(StartServiceControl); } protected override void OnStop() { base.OnStop(); String commandstop = @"service-control.bat --stop --all >> C:\\vCenterHAServiceStatus-%date:~4,2%%date:~7,2%%date:~10,4%.txt"; var StopServiceControl = new ProcessStartInfo("cmd.exe", "/c" + commandstop) { CreateNoWindow = true, UseShellExecute = false, WorkingDirectory = "C:\\Program Files\\VMware\\vCenter Server\\bin", }; var launcdoitstop = Process.Start(StopServiceControl); } } }
I am still working on refining it for clustering services, and any feedback would be appreciated it.
Thank you in advance.
(Abdullah)^2