/// <summary> /// Starts a server node with a given version. /// </summary> /// <param name="groupId">Maven artifact group id.</param> /// <param name="version">Product version.</param> /// <returns>Disposable object to stop the server.</returns> public static IDisposable Start(string groupId, string version) { IgniteArgumentCheck.NotNullOrEmpty(version, "version"); var pomWrapper = ReplaceIgniteVersionInPomFile(groupId, version, Path.Combine(JavaServerSourcePath, "pom.xml")); var process = new System.Diagnostics.Process { StartInfo = new ProcessStartInfo { FileName = Os.IsWindows ? "cmd.exe" : "/bin/bash", Arguments = Os.IsWindows ? string.Format("/c \"{0} {1}\"", MavenPath, MavenCommandExec) : string.Format("-c \"{0} {1}\"", MavenPath, MavenCommandExec.Replace("\"", "\\\"")), UseShellExecute = false, CreateNoWindow = true, WorkingDirectory = JavaServerSourcePath, RedirectStandardOutput = true, RedirectStandardError = true } }; process.Start(); var processWrapper = new DisposeAction(() => { process.KillProcessTree(); pomWrapper.Dispose(); }); try { var listDataReader = new ListDataReader(); process.AttachProcessConsoleReader(listDataReader, new IgniteProcessConsoleOutputReader()); // Wait for node to come up with a thin client connection. if (WaitForStart(listDataReader)) { return(processWrapper); } throw new Exception("Failed to start Java node: " + string.Join(",", listDataReader.GetOutput())); } catch (Exception) { processWrapper.Dispose(); throw; } }
/// <summary> /// Runs a process and waits for exit. /// </summary> private static void Execute(string file, string args, params IIgniteProcessOutputReader[] readers) { var startInfo = new ProcessStartInfo { FileName = file, Arguments = args, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false }; var process = new System.Diagnostics.Process { StartInfo = startInfo }; process.Start(); process.AttachProcessConsoleReader(readers); if (!process.WaitForExit(1000)) { process.Kill(); } }