public static bool StopAndUninstallService(Dictionary <string, string> installOptions, out string message) { bool ok = true; message = null; string configFile = null; if (installOptions != null && installOptions.ContainsKey(SynapseConfigParm)) { configFile = installOptions[SynapseConfigParm]; installOptions.Remove(SynapseConfigParm); } try { string sn = SynapseServerConfig.Deserialize(configFile).Service.Name; ServiceController sc = new ServiceController(sn); if (sc.Status == ServiceControllerStatus.Running) { Console.WriteLine($"\r\nStopping {sn}..."); sc.Stop(); sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMinutes(2)); } } catch (Exception ex) { message = ex.Message; ok = false; } if (ok) { ok = InstallOrUninstallService(install: false, configFile: configFile, message: out message); } return(ok); }
public SynapseServerServiceInstaller() { ServiceProcessInstaller processInstaller = new ServiceProcessInstaller(); ServiceInstaller serviceInstaller = new SynapseServiceInstaller(); //SynapseServerConfig.FileName is a static, so this will deserialize a custom config file if specified // since it was alreadt deserialized above at [SynapseServerConfig.DeserializeOrNew( serverRole, configFile );] (line 37) SynapseServerConfig config = SynapseServerConfig.Deserialize(); //set the privileges processInstaller.Account = ServiceAccount.LocalSystem; serviceInstaller.DisplayName = config.Service.DisplayName; string desc = config.Service.IsRoleController ? "Serves Plan commands to and receives Plan status from Synapse Nodes." : "Runs Plans, proxies to other Synapse Nodes."; serviceInstaller.Description = $"{desc} Use 'Synapse.Server /uninstall' to remove. Information at http://synapse.readthedocs.io/en/latest/."; serviceInstaller.StartType = ServiceStartMode.Automatic; //must be the same as what was set in Program's constructor serviceInstaller.ServiceName = config.Service.Name; this.Installers.Add(processInstaller); this.Installers.Add(serviceInstaller); }