/// <summary> /// Run method to start tomcat process in the worker role instances /// </summary> public override void Run() { // This is a sample worker implementation. Replace with your logic. DiagnosticsHelper.TraceInformation("ElasticSearch entry point called"); DiagnosticsHelper.TraceInformation("Configuring Elastic Search"); ConfigureElasticSearch(); DiagnosticsHelper.TraceInformation("Configured Elastic Search"); while (true) { Thread.Sleep(10000); Trace.WriteLine("Working", "Information"); try { if ((_process != null) && _process.HasExited) { DiagnosticsHelper.TraceInformation("ElasticSearch Process Exited. Hence recycling role."); RoleEnvironment.RequestRecycle(); return; } } catch (Exception ex) { DiagnosticsHelper.TraceError(ex.Message + " " + ex.StackTrace); throw new ApplicationException("Elastic Search Quit: " + ex.Message); } } }
/// <summary> /// Function to start Tomcat Process /// </summary> /// <param name="esLocation">The es location.</param> /// <param name="cacheLocation">The cache location.</param> /// <param name="workerIPs">The worker IP's.</param> /// <returns></returns> private Process StartESProcess(string esLocation, string cacheLocation, string workerIPs) { DiagnosticsHelper.TraceInformation("ElasticSearch - starting pricess at esLocation:" + esLocation + ",cacheLocation:" + cacheLocation + ",workerIPs:" + workerIPs); // initiating process var newProc = new Process(); // stream reader to get the output details of the running command try { //setting the required properties for the process newProc.StartInfo.UseShellExecute = false; newProc.StartInfo.RedirectStandardOutput = true; newProc.StartInfo.RedirectStandardError = true; newProc.StartInfo.RedirectStandardOutput = true; #if DEBUG newProc.StartInfo.CreateNoWindow = false; #endif #if !DEBUG newProc.StartInfo.CreateNoWindow = true; #endif newProc.EnableRaisingEvents = false; newProc.StartInfo.EnvironmentVariables.Remove("JAVA_HOME"); newProc.StartInfo.EnvironmentVariables.Add("JAVA_HOME", Path.Combine(esLocation, "jre7")); // setting the localsource path tomcatlocation to the environment variable catalina_home newProc.StartInfo.EnvironmentVariables.Add("ES_DATA", Path.Combine(Path.Combine(cacheLocation, "ElasticStorage"), "data")); newProc.StartInfo.EnvironmentVariables.Add("ES_HOSTS", workerIPs); // setting the file name bin\startup.bat in tomcatlocation of localresourcepath newProc.StartInfo.FileName = Path.Combine(esLocation, Settings.ElasticStartApp); DiagnosticsHelper.TraceInformation("ElasticSearch start command line: " + newProc.StartInfo.FileName); // starting process newProc.Start(); DiagnosticsHelper.TraceInformation("Done - Starting ElasticSearch"); newProc.OutputDataReceived += processToExecuteCommand_OutputDataReceived; newProc.ErrorDataReceived += processToExecuteCommand_ErrorDataReceived; newProc.BeginOutputReadLine(); newProc.BeginErrorReadLine(); newProc.Exited += Process_Exited; } catch (Exception ex) { // Logging the exceptiom DiagnosticsHelper.TraceError(ex.Message); throw; } return(newProc); }
private void ConfigureElasticSearch() { try { // Initializing RunES _elastic = new RunES(); var workerIPs = ListWorkerRoles(); DiagnosticsHelper.TraceInformation("OnStart workerIPs: " + workerIPs); DiagnosticsHelper.TraceInformation("OnStart CacheLocation: " + Settings.CacheDir); _process = _elastic.StartES(Settings.CacheDir, Settings.DefaultElasticPort, workerIPs); } catch (Exception ex) { DiagnosticsHelper.TraceInformation(ex.Message + " " + ex.StackTrace); DiagnosticsHelper.TraceError(ex.Message + " " + ex.StackTrace); Trace.Flush(); throw new ApplicationException("Can't configure Elastic Search: " + ex.Message); } }
private void processToExecuteCommand_ErrorDataReceived(object sender, DataReceivedEventArgs e) { DiagnosticsHelper.TraceError(e.Data); }