Beispiel #1
0
 // Constructor.
 public Timer(float seconds, FinishedHandler FinishedCallback = null, bool loop = true,
     bool clearOnRun = false, StartedHandler StartedCallback = null,
     StoppedHandler StoppedCallback = null, TickedHandler TickedCallback = null)
 {
     this.secondsTarget = seconds;
     this.Finished = FinishedCallback;
     this.loop = loop;
     this.clearOnRun = clearOnRun;
     this.Started = StartedCallback;
     this.Stopped = StoppedCallback;
     this.Ticked = TickedCallback;
     runner = new Runner(OnStarted, OnStopped);
 }
Beispiel #2
0
        private static void ExecuteBinaryInternal(EphemeralClusterConfiguration config, IConsoleLineHandler writer,
                                                  string binary, string description, StartedHandler startedHandler, params string[] arguments)
        {
            var command = $"{{{binary}}} {{{string.Join(" ", arguments)}}}";

            writer?.WriteDiagnostic($"{{{nameof(ExecuteBinary)}}} starting process [{description}] {command}");

            var timeout = TimeSpan.FromSeconds(420);
            var processStartArguments = new StartArguments(binary, arguments)
            {
                Environment = new Dictionary <string, string>
                {
                    { config.FileSystem.ConfigEnvironmentVariableName, config.FileSystem.ConfigPath },
                    { "ES_HOME", config.FileSystem.ElasticsearchHome }
                }
            };

            var result = startedHandler != null
                                ? Proc.Start(processStartArguments, timeout, new ConsoleOutColorWriter(), startedHandler)
                                : Proc.Start(processStartArguments, timeout, new ConsoleOutColorWriter());

            if (!result.Completed)
            {
                throw new Exception($"Timeout while executing {description} exceeded {timeout}");
            }

            if (result.ExitCode != 0)
            {
                throw new Exception(
                          $"Expected exit code 0 but received ({result.ExitCode}) while executing {description}: {command}");
            }

            var errorOut = result.ConsoleOut.Where(c => c.Error).ToList();

            // this manifested when calling certgen on versions smaller then 5.2.0
            if (errorOut.Any() && config.Version < "5.2.0")
            {
                errorOut = errorOut.Where(e => !e.Line.Contains("No log4j2 configuration file found")).ToList();
            }

            if (errorOut.Any(e =>
                             !string.IsNullOrWhiteSpace(e.Line) && !e.Line.Contains("usage of JAVA_HOME is deprecated")) &&
                !binary.Contains("plugin") && !binary.Contains("cert"))
            {
                throw new Exception(
                          $"Received error out with exitCode ({result.ExitCode}) while executing {description}: {command}");
            }

            writer?.WriteDiagnostic(
                $"{{{nameof(ExecuteBinary)}}} finished process [{description}] {{{result.ExitCode}}}");
        }
Beispiel #3
0
 // Constructor.
 public Timer(float seconds, FinishedHandler FinishedCallback = null, bool loop   = true,
              bool clearOnRun = false, StartedHandler StartedCallback             = null,
              StoppedHandler StoppedCallback = null, TickedHandler TickedCallback = null)
 {
     if (seconds <= 0.0f)
     {
         Debug.LogError("Prevented instantiation of a timer that loops every " + seconds
                        + " seconds. Make sure timers run for longer than 0 seconds. " +
                        "The timer has been set to loop every second to prevent an infinite loop.");
         seconds = 1.0f;
     }
     this.secondsTarget = seconds;
     this.Finished      = FinishedCallback;
     this.loop          = loop;
     this.clearOnRun    = clearOnRun;
     this.Started       = StartedCallback;
     this.Stopped       = StoppedCallback;
     this.Ticked        = TickedCallback;
     runner             = new Runner(OnStarted, OnStopped);
 }
Beispiel #4
0
        static public void Start(StartedHandler started)
        {
            Log.Spew("Starting daemon");

            string beagled;

            beagled = Environment.GetEnvironmentVariable("BEAGLED_COMMAND");

            string args;

            args = "--debug-memory --bg --backend Files";

            if (UseHeapBuddy)
            {
                args += " --heap-buddy";
            }

            Process p;

            p = new Process();
            p.StartInfo.UseShellExecute = false;

            p.StartInfo.FileName  = beagled;
            p.StartInfo.Arguments = args;

            p.StartInfo.EnvironmentVariables ["BEAGLE_HOME"]             = Beagle.Util.PathFinder.HomeDir;
            p.StartInfo.EnvironmentVariables ["BEAGLE_EXERCISE_THE_DOG"] = "1";
            p.StartInfo.EnvironmentVariables ["BEAGLE_UNDER_BLUDGEON"]   = "1";
            p.StartInfo.EnvironmentVariables ["BEAGLE_HEAP_BUDDY_DIR"]   = Path.Combine(Beagle.Util.PathFinder.HomeDir,
                                                                                        ".bludgeon");

            p.Start();

            WaitForStartClosure closure;

            closure = new WaitForStartClosure(p, started);
            closure.Start();
        }
Beispiel #5
0
			public WaitForStartClosure (Process process, StartedHandler started)
			{
				this.process = process;
				this.started = started;
			}
Beispiel #6
0
		static public void Start (StartedHandler started)
		{
			Log.Spew ("Starting daemon");
			
			string beagled;
			beagled = Environment.GetEnvironmentVariable ("BEAGLED_COMMAND");

			string args;
			args = "--debug-memory --bg --backend Files";

			if (UseHeapBuddy)
				args += " --heap-buddy";
			
			Process p;
			p = new Process ();
			p.StartInfo.UseShellExecute = false;
			
			p.StartInfo.FileName = beagled;
			p.StartInfo.Arguments = args;

			p.StartInfo.EnvironmentVariables ["BEAGLE_HOME"] = Beagle.Util.PathFinder.HomeDir;
			p.StartInfo.EnvironmentVariables ["BEAGLE_EXERCISE_THE_DOG"] = "1";
			p.StartInfo.EnvironmentVariables ["BEAGLE_UNDER_BLUDGEON"] = "1";
			p.StartInfo.EnvironmentVariables ["BEAGLE_HEAP_BUDDY_DIR"] = Path.Combine (Beagle.Util.PathFinder.HomeDir,
												   ".bludgeon");

			p.Start ();
			
			WaitForStartClosure closure;
			closure = new WaitForStartClosure (p, started);
			closure.Start ();
		}
Beispiel #7
0
        /// <summary>
        /// Start a program and get notified of lines in realtime through <paramref name="lineHandler"/> unlike <see cref="Start(string,string[])"/>
        /// This won't capture all lines on the returned object and won't default to writing to the Console.
        /// </summary>
        /// <param name="timeout">The maximum runtime of the started program</param>
        /// <param name="started">A callback when the process is ready to receive standard in writes</param>
        /// <param name="lineHandler">
        /// An implementation of <see cref="IConsoleLineHandler"/> that receives every line as <see cref="LineOut"/> or the <see cref="Exception"/> that occurs while running
        /// </param>
        /// <returns>The exit code and whether the process completed</returns>
        public static ProcessResult StartRedirected(StartArguments arguments, TimeSpan timeout, StartedHandler started, IConsoleLineHandler lineHandler = null)
        {
            using (var composite = new CompositeDisposable())
            {
                var process = new ObservableProcess(arguments);
                if (started != null)
                {
                    process.ProcessStarted += started;
                }

                Exception seenException = null;
                composite.Add(process);
                composite.Add(process.SubscribeLines(
                                  l => lineHandler?.Handle(l),
                                  e =>
                {
                    seenException = e;
                    lineHandler?.Handle(e);
                })
                              );

                var completed = process.WaitForCompletion(timeout);
                if (seenException != null)
                {
                    ExceptionDispatchInfo.Capture(seenException).Throw();
                }
                return(new ProcessResult(completed, process.ExitCode));
            }
        }
Beispiel #8
0
 /// <summary>
 /// Start a program and get notified of lines in realtime through <paramref name="lineHandler"/> unlike <see cref="Start(string,string[])"/>
 /// This won't capture all lines on the returned object and won't default to writing to the Console.
 /// </summary>
 /// <param name="timeout">The maximum runtime of the started program</param>
 /// <param name="started">A callback when the process is ready to receive standard in writes</param>
 /// <param name="lineHandler">
 /// An implementation of <see cref="IConsoleLineHandler"/> that receives every line as <see cref="LineOut"/> or the <see cref="Exception"/> that occurs while running
 /// </param>
 /// <returns>The exit code and whether the process completed</returns>
 public static ProcessResult StartRedirected(IConsoleLineHandler lineHandler, string bin, TimeSpan timeout, StartedHandler started, params string[] arguments) =>
 StartRedirected(new StartArguments(bin, arguments), timeout, started, lineHandler);
Beispiel #9
0
 // Change the timer's started callback function.
 public void SubscribeToStarted(StartedHandler Callback)
 {
     Started = Callback;
 }
Beispiel #10
0
 protected static void ExecuteBinary(EphemeralClusterConfiguration config, IConsoleLineHandler writer,
                                     string binary, string description, StartedHandler startedHandler, params string[] arguments) =>
 ExecuteBinaryInternal(config, writer, binary, description, startedHandler, arguments);
Beispiel #11
0
 public WaitForStartClosure(Process process, StartedHandler started)
 {
     this.process = process;
     this.started = started;
 }
Beispiel #12
0
        /// <summary> Starts a program and captures the output while writing to the console in realtime during execution </summary>
        /// <param name="timeout">The maximum runtime of the started program</param>
        /// <param name="started">A callback when the process is ready to receive standard in writes</param>
        /// <param name="consoleOutWriter">
        /// An implementation of <see cref="IConsoleOutWriter"/> that takes care of writing to the console
        /// <para>defaults to <see cref="ConsoleOutColorWriter"/> which writes standard error messages in red</para>
        /// </param>
        /// <returns>An object holding a list of console out lines, the exit code and whether the process completed</returns>
        public static ProcessCaptureResult Start(StartArguments arguments, TimeSpan timeout, IConsoleOutWriter consoleOutWriter, StartedHandler started)
        {
            using (var composite = new CompositeDisposable())
            {
                var process = new ObservableProcess(arguments);
                if (started != null)
                {
                    process.ProcessStarted += started;
                }
                consoleOutWriter = consoleOutWriter ?? new ConsoleOutColorWriter();

                Exception seenException = null;
                var       consoleOut    = new List <LineOut>();
                composite.Add(process);
                composite.Add(process.SubscribeLinesAndCharacters(
                                  consoleOut.Add,
                                  e => seenException = e,
                                  consoleOutWriter.Write,
                                  consoleOutWriter.Write
                                  )
                              );

                var completed = process.WaitForCompletion(timeout);
                if (seenException != null)
                {
                    ExceptionDispatchInfo.Capture(seenException).Throw();
                }
                return(new ProcessCaptureResult(completed, consoleOut, process.ExitCode));
            }
        }
Beispiel #13
0
 /// <summary> Starts a program and captures the output while writing to the console in realtime during execution </summary>
 /// <param name="timeout">The maximum runtime of the started program</param>
 /// <param name="started">A callback when the process is ready to receive standard in writes</param>
 /// <param name="consoleOutWriter">
 /// An implementation of <see cref="IConsoleOutWriter"/> that takes care of writing to the console
 /// <para>defaults to <see cref="ConsoleOutColorWriter"/> which writes standard error messages in red</para>
 /// </param>
 /// <returns>An object holding a list of console out lines, the exit code and whether the process completed</returns>
 public static ProcessCaptureResult Start(string bin, TimeSpan timeout, IConsoleOutWriter consoleOutWriter, StartedHandler started, params string[] arguments) =>
 Start(new StartArguments(bin, arguments), timeout, consoleOutWriter, started);
Beispiel #14
0
 /// <summary> Starts a program and captures the output while writing to the console in realtime during execution </summary>
 /// <param name="timeout">The maximum runtime of the started program</param>
 /// <param name="started">A callback when the process is ready to receive standard in writes</param>
 /// <returns>An object holding a list of console out lines, the exit code and whether the process completed</returns>
 public static ProcessCaptureResult Start(string bin, TimeSpan timeout, StartedHandler started, params string[] arguments) =>
 Start(bin, timeout, null, started, arguments);
Beispiel #15
0
 public void SetStartedCallback(StartedHandler Callback)
 {
     Started = Callback;
 }
Beispiel #16
0
 public Runner(StartedHandler StartedCallback = null, StoppedHandler StoppedCallback = null)
 {
     Started = StartedCallback;
     Stopped = StoppedCallback;
 }