Merge pull request #1408 from tgstation/aa/service-runner-change

Service installer will now ask to remove old ones
This commit is contained in:
Jordan Dominion
2022-10-08 12:00:12 -04:00
committed by GitHub
@@ -118,6 +118,32 @@ namespace Tgstation.Server.Host.Service
{
if (Uninstall)
return; // oh no, it's retarded...
// First check if the service already exists
if (Environment.UserInteractive)
foreach (ServiceController sc in ServiceController.GetServices())
if (sc.ServiceName == "tgstation-server" || sc.ServiceName == "tgstation-server-4")
{
DialogResult result = MessageBox.Show($"You already have another TGS service installed ({sc.ServiceName}). Would you like to uninstall it now? Pressing \"No\" will cancel this install.", "TGS Service", MessageBoxButtons.YesNo);
if (result != DialogResult.Yes)
return; // is this needed after exit?
// Stop it first to give it some cleanup time
if (sc.Status == ServiceControllerStatus.Running)
{
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped);
}
// And remove it
using (ServiceInstaller si = new ServiceInstaller())
{
si.Context = new InstallContext($"old-{sc.ServiceName}-uninstall.log", null);
si.ServiceName = sc.ServiceName;
si.Uninstall(null);
}
}
using (var processInstaller = new ServiceProcessInstaller())
using (var installer = new ServiceInstaller())
{