/// <summary> /// Applies the plan. /// </summary> /// <returns></returns> private dynamic ApplyPlan() { Logger.Info("Applying : " + newSpec.ToString()); if (oldPlan.Deployment.Value != string.Empty && oldPlan.Deployment.Value != newPlan.Deployment.Value) { MessageHandlerException exception = new MessageHandlerException(string.Format("attempt to apply {0} to {1}", oldPlan.Deployment.Value, newPlan.Deployment.Value)); Logger.Error(exception.Message); throw exception; } if (newPlan.Configured) { try { Monit.GetInstance().StopServices(); // TODO make sure processes have exited, even if windows reports services as stopped Thread.Sleep(10000); ApplyJob(); ApplyPackage(); ConfigureJob(); } catch (Exception ex) { MessageHandlerException exception = new MessageHandlerException(ex.Message, ex); throw exception; } } Config.State.Write(newSpec); return newSpec; }
private object RunDrainScript(string jobUpdated, string hashUpdated, string[] updatedPackages) { int result =0; string standardOutput = string.Empty; string standardError = string.Empty; Logger.Info(string.Format(CultureInfo.InvariantCulture, "Running drain script with job updated: {0}, hash updated: {1} and updated packages {2}", jobUpdated, hashUpdated, string.Join(" ", updatedPackages))); ProcessStartInfo info = new ProcessStartInfo(); info.FileName = drainFile; info.EnvironmentVariables.Add("job_change", jobUpdated); info.EnvironmentVariables.Add("hash_change", hashUpdated); info.EnvironmentVariables.Add("updated_packages", String.Join(" ", updatedPackages)); info.RedirectStandardOutput = true; info.RedirectStandardError = true; info.UseShellExecute = false; using (System.Diagnostics.Process p = new Process()) { p.StartInfo = info; p.Start(); p.WaitForExit(); result = p.ExitCode; standardOutput = p.StandardOutput.ReadToEnd(); standardError = p.StandardError.ReadToEnd(); } if (!String.IsNullOrEmpty(standardError)) { string errorMessage = string.Format(CultureInfo.InvariantCulture, "Drain script error exit {0} : {1}", result, standardError); MessageHandlerException massageHandlerException = new MessageHandlerException(errorMessage); Logger.Error(errorMessage); throw massageHandlerException; } else { Logger.Info(string.Format(CultureInfo.InvariantCulture, "Finished running drain script, output :{0}", standardOutput)); } return result; }