示例#1
0
        public void Stop()
        {
            if (Stopped)
            {
                return;
            }

            lock (lockStop)
            {
                if (Stopped)
                {
                    return;
                }

                Log.Info("Stopping admin process");

                AppDomain.CurrentDomain.ProcessExit -= ProcessExit;

                try
                {
                    CancelOperationTS.Cancel();

                    HandshakeWithinTimeout?.Abort();

                    SendTerminateToAdminProcess();

                    AdminProcessAliveChecker?.Stop();

                    ShutdownWebSocketServerServices();

                    TerminateAdminProcess();

                    ShutdownWebSocketServer();

                    if (!AdminComConfig.UnencryptedServerCom)
                    {
                        Log.Info("Disposing cert");
                        ServerCert?.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
                finally
                {
                    Stopped = true;
                }

                Log.Debug("Done");
            }
        }
示例#2
0
        public void Start()
        {
            Log.Info("Start");
            Stopped = false;

            AppDomain.CurrentDomain.ProcessExit += ProcessExit;

            AdminComConfig.ParentPID = Process.GetCurrentProcess().Id;

            LaunchWebSocketServer();

            StartAdminProcess();

            AdminProcessAliveChecker = new ProcessAliveChecker(AdminProcessID.Value, TimeSpan.FromSeconds(5), () =>
            {
                Log.Error($"Unable to locate PID={AdminProcessID.Value} of admin-process, assuming crash; Stopping...");
                Stop();

                throw new OperationCanceledException($"SERVER_SHUTDOWN: Unable to locate PID={AdminProcessID.Value} of admin-process, assuming crash");
            });
            AdminProcessAliveChecker.Start();

            Log.Info("Waiting for handshake...");
            if (!HandshakeWithinTimeout
                .StartTimeout(AdminComConfig.StartInactivityShutdownTimeout)
                .Result)
            {
                Log.Error($"No handshake from Admin-process within timeout[='{AdminComConfig.StartInactivityShutdownTimeout}']; Stopping...");
                Stop();

                throw new OperationCanceledException($"SERVER_SHUTDOWN: No handshake from Admin-process within timeout[='{AdminComConfig.StartInactivityShutdownTimeout}']");
            }
            else
            {
                Log.Info("Handshake successful");
            }
        }