static int RunMain(string[] arguments) { const int Result = 0; AppDomain.CurrentDomain.UnhandledException += (sender, args) => { Dev2Logger.Fatal("Server has crashed!!!", args.ExceptionObject as Exception, "Warewolf Fatal"); }; if (Environment.UserInteractive || (arguments.Count() > 0 && arguments[0] == "--interactive")) { Dev2Logger.Info("** Starting In Interactive Mode **", GlobalConstants.WarewolfInfo); using (_singleton = new ServerLifecycleManager(arguments)) { _singleton.Run(true); } _singleton = null; } else { Dev2Logger.Info("** Starting In Service Mode **", GlobalConstants.WarewolfInfo); using (var service = new ServerLifecycleManagerService()) { ServiceBase.Run(service); } } return(Result); }
internal static async Task <int> RunMain(string[] arguments) { SetWorkingDirectory(); const int Result = 0; if (Environment.UserInteractive || (arguments.Any() && arguments[0] == "--interactive")) { Dev2Logger.Info("** Starting In Interactive Mode **", GlobalConstants.WarewolfInfo); var manager = new ServerLifecycleManager(new ServerEnvironmentPreparer()); var runTask = manager.Run(new LifeCycleInitializationList()); runTask.Wait(); WaitForUserExit(manager); } else { Dev2Logger.Info("** Starting In Service Mode **", GlobalConstants.WarewolfInfo); using (var service = new ServerLifecycleManagerService()) { ServiceBase.Run(service); if (!service.RunSuccessful) { Dev2Logger.Warn("** Service Mode Failed to Start **", GlobalConstants.WarewolfWarn); return(-1); } } } return(Result); }
static void WaitForUserExit(ServerLifecycleManager manager) { Console.WriteLine("Press <ENTER> to terminate service and/or web server if started"); if (EnvironmentVariables.IsServerOnline) { Pause(); } else { Console.Write("Failed to start Server"); } manager.Stop(false, 0); }
internal static async Task <int> RunMain(string[] arguments) { SetWorkingDirectory(); const int Result = 0; #if DEBUG if (Environment.GetEnvironmentVariable("WAREWOLF_SERVER_DEBUG") == "1") { Dev2Logger.Info("** Starting In Debugging Mode **", GlobalConstants.WarewolfInfo); while (!Debugger.IsAttached) { Thread.Sleep(3000); Console.WriteLine("Still waiting for remote debugging..."); } Console.WriteLine("Ready for remote debugging."); } #endif if (Environment.UserInteractive || (arguments.Any() && arguments[0] == "--interactive")) { Dev2Logger.Info("** Starting In Interactive Mode **", GlobalConstants.WarewolfInfo); var manager = new ServerLifecycleManager(new ServerEnvironmentPreparer()); var runTask = manager.Run(new LifeCycleInitializationList()); runTask.Wait(); WaitForUserExit(manager); } else { Dev2Logger.Info("** Starting In Service Mode **", GlobalConstants.WarewolfInfo); using (var service = new ServerLifecycleManagerService()) { ServiceBase.Run(service); if (!service.RunSuccessful) { Dev2Logger.Warn("** Service Mode Failed to Start **", GlobalConstants.WarewolfWarn); return(-1); } } } return(Result); }
static int RunMain(string[] arguments) { var result = 0; try { CommandLineParameters options = new CommandLineParameters(); CommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error)); if(!parser.ParseArguments(arguments, options)) { return 80; } bool commandLineParameterProcessed = false; if(options.Install) { Dev2Logger.Log.Info("Starting Install"); commandLineParameterProcessed = true; if(!EnsureRunningAsAdministrator(arguments)) { Dev2Logger.Log.Info("Cannot install because the server is not running as an admin user"); return result; } if(!WindowsServiceManager.Install()) { result = 81; Dev2Logger.Log.Info("Install Success Result is 81"); } } if(options.StartService) { Dev2Logger.Log.Info("Starting Service"); commandLineParameterProcessed = true; if(!EnsureRunningAsAdministrator(arguments)) { Dev2Logger.Log.Info("Cannot start because the server is not running as an admin user"); return result; } if(!WindowsServiceManager.StartService(null)) { Dev2Logger.Log.Info("Starting Service success. result 83"); result = 83; } } if(options.StopService) { Dev2Logger.Log.Info("Stopping Service"); commandLineParameterProcessed = true; if(!EnsureRunningAsAdministrator(arguments)) { Dev2Logger.Log.Info("Cannot stop because the server is not running as an admin user"); return result; } if(!WindowsServiceManager.StopService(null)) { Dev2Logger.Log.Info("Stopping Service success. result 84"); result = 84; } } if(options.Uninstall) { Dev2Logger.Log.Info("Uninstall Service"); commandLineParameterProcessed = true; if(!EnsureRunningAsAdministrator(arguments)) { Dev2Logger.Log.Info("Cannot uninstall because the server is not running as an admin user"); return result; } if(!WindowsServiceManager.Uninstall()) { Dev2Logger.Log.Info("Uninstall Service success. result 92"); result = 82; } } if(commandLineParameterProcessed) { Dev2Logger.Log.Info("Command line processed. Returning"); return result; } AppDomain.CurrentDomain.UnhandledException += (sender, args) => { Dev2Logger.Log.Fatal("Server has crashed!!!", args.ExceptionObject as Exception); }; if(Environment.UserInteractive || options.IntegrationTestMode) { Dev2Logger.Log.Info("** Starting In Interactive Mode ( " + options.IntegrationTestMode + " ) **"); using(_singleton = new ServerLifecycleManager(arguments)) { result = _singleton.Run(true); } _singleton = null; } else { Dev2Logger.Log.Info("** Starting In Service Mode **"); // running as service using(var service = new ServerLifecycleManagerService()) { ServiceBase.Run(service); } } } catch(Exception err) { Dev2Logger.Log.Error("Error Starting Server", err); // ReSharper disable InvokeAsExtensionMethod Dev2Logger.Log.Error("Error Starting Server. Stack trace", err); // ReSharper restore InvokeAsExtensionMethod throw; } return result; }
protected override void OnStart(string[] args) { Dev2Logger.Log.Info("** Service Started **"); _singleton = new ServerLifecycleManager(null); _singleton.Run(false); }
protected override void OnStart(string[] args) { Dev2Logger.Info("** Service Started **", GlobalConstants.WarewolfInfo); _singleton = new ServerLifecycleManager(null); _singleton.Run(false); }