public static void DeserialzeConfig(string[] args) { string configFile = SynapseServerConfig.FileName; if (args != null && args.Length > 0) { string arg0 = args[0].ToLower(); List <string> parms = (new string[] { "install", "i", "uninstall", "u", "genconfig", "gc" }).ToList(); if (!parms.Contains(arg0)) { if (File.Exists(arg0)) { configFile = args[0]; //this line supports "synapse.server xx.config.yaml" for running as service } else { FileNotFoundException ex = new FileNotFoundException($"Could not find startup config file [{args[0]}].", args[0]); if (Environment.UserInteractive) { WriteHelpAndExit(ex.Message); } else { throw ex; } } } } Config = SynapseServerConfig.DeserializeOrNew(ServerRole.Server, configFile); }
public static SynapseServerConfig DeserializeOrNew(ServerRole role, string fileName = null) { SynapseServerConfig config = null; int port = ((role & ServerRole.Controller) == ServerRole.Controller) ? 20000 : 20001; if (!string.IsNullOrWhiteSpace(fileName)) { FileName = fileName; } if (!File.Exists(FileName)) { config = new SynapseServerConfig(); config.WebApi.Port = port; config.Service.Name = $"Synapse.{role}"; config.Service.DisplayName = $"Synapse {role}"; config.Service.Role = role; if (config.Service.IsRoleController) { WebApiConfig node = new Services.WebApiConfig() { Host = config.WebApi.Host, IsSecure = config.WebApi.IsSecure }; node.Port = config.Service.IsRoleServer ? 20000 : 20001; config.Controller.Configure(node.ToUri(Environment.UserInteractive)); } if (!config.Service.IsRoleController) { config.Controller = null; } if (!config.Service.IsRoleNode) { config.Node = null; } config.Serialize(); } else { config = YamlHelpers.DeserializeFile <SynapseServerConfig>(FileName); } return(config); }
public static bool InstallAndStartService(ServerRole serverRole, Dictionary <string, string> installOptions, out string message) { message = null; bool startService = true; string configFile = null; if (installOptions != null) { const string run = "run"; if (installOptions.ContainsKey(run)) { bool.TryParse(installOptions[run], out startService); installOptions.Remove(run); } if (installOptions.ContainsKey(SynapseConfigParm)) { configFile = installOptions[SynapseConfigParm]; installOptions.Remove(SynapseConfigParm); } } SynapseServerConfig config = SynapseServerConfig.DeserializeOrNew(serverRole, configFile); bool ok = InstallOrUninstallService(install: true, configFile: configFile, message: out message); if (ok && startService) { try { Console.Write($"\r\nStarting {config.Service.Name}... "); ServiceController sc = new ServiceController(config.Service.Name); sc.Start(); sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMinutes(2)); Console.WriteLine(sc.Status); } catch (Exception ex) { Console.WriteLine(); message = ex.Message; ok = false; } } return(ok); }
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); }
public static void InstallService(string[] args) { if (Environment.UserInteractive) { if (args.Length > 0) { bool ok = false; string message = string.Empty; bool cliParseError = false; Dictionary <string, string> options = args.Length > 1 ? CmdLineUtilities.ParseCmdLine(args, 1, ref cliParseError, ref message, null, true) : null; bool quiet = false; if (!cliParseError) { if (options != null && options.ContainsKey("quiet")) { bool.TryParse(options["quiet"], out quiet); options.Remove("quiet"); } } string arg0 = args[0].ToLower(); if (arg0 == "install" || arg0 == "i") { if (!cliParseError) { ok = InstallUtility.InstallAndStartService(serverRole: ServerRole.Server, installOptions: options, message: out message); } } else if (arg0 == "uninstall" || arg0 == "u") { ok = InstallUtility.StopAndUninstallService(installOptions: options, message: out message); } else if (arg0 == "genconfig" || arg0 == "gc") { string configFile = null; if (!cliParseError) { if (options != null && options.ContainsKey("filepath")) { configFile = options["filepath"]; } } SynapseServerConfig.DeserializeOrNew(ServerRole.Server, configFile); ok = true; } if (!ok) { WriteHelpAndExit(message, quiet); } else { Environment.Exit(0); } } else { WriteHelpAndExit(); } } }