/// <summary> /// Stops this instance. /// </summary> public override void StopProcess() { // Remove event listeners. if (logWatcher != null) { logWatcher.Changed -= LogWatcher_FileLog; logWatcher.Dispose(); logWatcher = null; } WrappedProcess?.Kill(); WrappedProcess = null; }
/// <summary> /// Starts a new process. /// </summary> public IMongoDbProcess Start(string binariesDirectory, string dataDirectory, int port, bool doNotKill) { string fileName = @"{0}\{1}".Formatted(binariesDirectory, MongoDbDefaults.MongodExecutable); string arguments = @"--dbpath ""{0}"" --port {1} --nohttpinterface --nojournal".Formatted(dataDirectory, port); WrappedProcess wrappedProcess = ProcessControl.ProcessFactory(fileName, arguments); wrappedProcess.DoNotKill = doNotKill; string windowTitle = "mongod | port: {0}".Formatted(port); ProcessOutput output = ProcessControl.StartAndWaitForReady(wrappedProcess, 5, ProcessReadyIdentifier, windowTitle); MongoDbProcess mongoDbProcess = new MongoDbProcess(wrappedProcess) { ErrorOutput = output.ErrorOutput, StandardOutput = output.StandardOutput }; return(mongoDbProcess); }
/// <summary> /// Starts a new process. /// </summary> public IMongoDbProcess Start(string binariesDirectory, string dataDirectory, int port, bool doNotKill) { string fileName = @"{0}{1}{2}".Formatted(binariesDirectory, System.IO.Path.DirectorySeparatorChar.ToString(), MongoDbDefaults.MongodExecutable); string arguments = @"--sslMode disabled --dbpath ""{0}"" --port {1} --nojournal --bind_ip 127.0.0.1".Formatted(dataDirectory, port); WrappedProcess wrappedProcess = ProcessControl.ProcessFactory(fileName, arguments); wrappedProcess.DoNotKill = doNotKill; string windowTitle = "mongod | port: {0}".Formatted(port); ProcessOutput output = ProcessControl.StartAndWaitForReady(wrappedProcess, 5, ProcessReadyIdentifier, windowTitle); MongoDbProcess mongoDbProcess = new MongoDbProcess(wrappedProcess) { ErrorOutput = output.ErrorOutput, StandardOutput = output.StandardOutput }; return(mongoDbProcess); }
/// <summary> /// Shuts down the hub and all registered nodes. /// </summary> public override void StopProcess() { if (!IsRunning()) { return; } foreach (var node in registeredNodes) { node.StopProcess(); } registeredNodes.Clear(); if (Options.Servlets.Contains(DefaultServletNames.LifeCycleServlet)) { // Send shutdown request. var shutDownUri = new Uri(Uri, "lifecycle-manager?action=shutdown"); using (var httpClient = new HttpClient()) { httpClient .GetAsync(shutDownUri) .Wait(TimeSpan.FromSeconds(10)); } WrappedProcess.WaitForExit(10000); } else { // Terminate the hub. WrappedProcess.Kill(); WrappedProcess.WaitForExit(10000); WrappedProcess.Dispose(); } WrappedProcess = null; }
/// <summary> /// Starts the node process. /// </summary> public override void StartProcess() { // Check if port is busy. var port = Options.Port ?? ExtractPort(Options.Host) ?? 0; if (IsLocalPortBusy(port, TimeSpan.FromSeconds(1))) { throw new Exception(""); } signal = new AutoResetEvent(false); var useLog = !String.IsNullOrEmpty(Options.Log); var startInfo = new ProcessStartInfo { Arguments = GetCommandLineArguments(), FileName = "java", RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false }; // Start the process. WrappedProcess = Process.Start(startInfo); // Wait for file to exists. if (useLog) { // Stream file. var fileInfo = new FileInfo(Options.Log); logWatcher = new FileSystemWatcher { NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName, Path = fileInfo.DirectoryName }; logWatcher.Changed += LogWatcher_FileLog; logWatcher.Changed += LogWatcher_FileDataRecieved; logWatcher.EnableRaisingEvents = true; } else { // Stream stderr/stdout. WrappedProcess.ErrorDataReceived += LocalNodeProcess_StdOutOutputDataReceived; } // Always listen to stdout/stderr. WrappedProcess.OutputDataReceived += NodeProcess_StdOutLog; WrappedProcess.ErrorDataReceived += NodeProcess_StdOutLog; WrappedProcess.BeginOutputReadLine(); WrappedProcess.BeginErrorReadLine(); // Wait for the node to start. signal.WaitOne(TimeSpan.FromSeconds(30)); // Remove unecessary event listeners. if (useLog) { logWatcher.Changed -= LogWatcher_FileDataRecieved; } else { WrappedProcess.ErrorDataReceived -= LocalNodeProcess_StdOutOutputDataReceived; } if (WrappedProcess.HasExited) { Dispose(); throw new Exception("Failed to start the node process."); } signal.Dispose(); }
/// <summary> /// Starts this instance. /// </summary> /// <exception cref="Exception">Failed to start the hub process.</exception> public override void StartProcess() { // Check if port is busy. var port = Options.PortNumber ?? ExtractPort(Options.Host) ?? 4444; if (IsLocalPortBusy(port, TimeSpan.FromSeconds(1))) { throw new Exception($"Port {port} wasn't available."); } var useLog = !String.IsNullOrEmpty(Options.Log); var hubStartupInfo = new ProcessStartInfo { Arguments = GetCommandLineArguments(), FileName = "java", RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false }; // Start the process. WrappedProcess = Process.Start(hubStartupInfo); if (useLog) { // Stream file. var fileInfo = new FileInfo(Options.Log); logWatcher = new FileSystemWatcher { NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName, Path = fileInfo.DirectoryName }; logWatcher.Changed += LogWatcher_Log; logWatcher.Changed += LogWatcher_OutputDataRecieved; logWatcher.EnableRaisingEvents = true; } else { // Stream stderr/stdout. WrappedProcess.ErrorDataReceived += HubProcess_OutputDataReceived; } // Always listen to stdout/stderr. WrappedProcess.OutputDataReceived += HubProcess_Log; WrappedProcess.ErrorDataReceived += HubProcess_Log; WrappedProcess.BeginOutputReadLine(); WrappedProcess.BeginErrorReadLine(); // Wait for hub to start. signal.WaitOne(TimeSpan.FromSeconds(30)); // Check if the register url is null. if (String.IsNullOrEmpty(NodeRegisterUrl?.ToString())) { throw new Exception("Failed to set the node register url."); } // Remove unecessary event listeners. if (useLog) { logWatcher.Changed -= LogWatcher_OutputDataRecieved; } else { WrappedProcess.ErrorDataReceived -= HubProcess_OutputDataReceived; } if (WrappedProcess.HasExited) { Dispose(); throw new Exception("Failed to start the hub process."); } }