Ejemplo n.º 1
0
        /// <summary>
        /// Triggered on receiving a termination request. Clean up self, terminate all child process.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnProcessExit(object sender, EventArgs e)
        {
            LogMuxer.Instance.Info("Quitting");
            Wrapper?.Stop();

            // shut down all child processes
            foreach (var pid in ProgramWrapper.GetChildProcessIds(ProgramWrapper.SelfProcessId))
            {
                ProgramWrapper.QuitProcess(Process.GetProcessById(pid));
            }
        }
Ejemplo n.º 2
0
        internal void Stop()
        {
            if (hasStopped)
            {
                return;
            }
            LogMuxer.Instance.Debug("Killing child processes");
            foreach (var wrapper in _programPool)
            {
                wrapper.Stop();
            }

            // First we notify all running process to quit
            LogMuxer.Instance.Debug("Killing subprocesses");
            foreach (var pid in ProgramWrapper.GetChildProcessIds(ProgramWrapper.SelfProcessId))
            {
                ProgramWrapper.QuitProcess(Process.GetProcessById(pid));
            }

            // ExecStop
            // only if the service started successfully
            if (hasStartedSuccessfully)
            {
                LogMuxer.Instance.Debug("Executing ExecStop");
                for (var i = 0; i < Globals.Config.ExecStop.Count; ++i)
                {
                    Run(Globals.Config.ExecStop[i], "ExecStop", i, isAsync: false);
                }
            }

            // ExecStopPost
            LogMuxer.Instance.Debug("Executing ExecStopPost");
            for (var i = 0; i < Globals.Config.ExecStopPost.Count; ++i)
            {
                Run(Globals.Config.ExecStopPost[i], "ExecStopPost", i, isAsync: false);
            }

            OnQuit?.Invoke(this, null);

            hasStopped = true;
        }