示例#1
0
        protected void Init()
        {
            StarterPIDAliveChecker = new ProcessAliveChecker(Config.ParentPID, TimeSpan.FromSeconds(5), () =>
            {
                Log.Error($"Unable to locate PID={Config.ParentPID} of parent-process, assuming crash; Stopping...");
                Stop();
            });

            Log.Info($"Doing inital check if starter process[PID={Config.ParentPID}] is alive");
            if (!ProcessAliveChecker.CheckIfPIDAlive(Config.ParentPID))
            {
                throw new ArgumentException($"{nameof(Config.ParentPID)}={Config.ParentPID} not found!");
            }

            Log.Info($"Starting {nameof(StarterPIDAliveChecker)}; StarterPID={Config.ParentPID}");
            StarterPIDAliveChecker.Start();
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns><code>true</code> if the lockfile is valid, other wise <code>false</code></returns>
        protected bool ValidateLockFile()
        {
            if (LockFile.PID < 0)
            {
                Log.Warn($"Lockfile contains invalid PID='{LockFile.PID}'");
                return(false);
            }

            if (!ProcessAliveChecker.CheckIfPIDAlive(LockFile.PID))
            {
                Log.Warn($"PID of lockfile '{LockFile.PID}' is not alive");
                return(false);
            }

            if ((DateTime.Now - LockFile.UpdateDate) >= LockFileConfig.LockFileInvalidAfter)
            {
                Log.Warn($"Lockfile was updated by a process at {LockFile.UpdateDate} which is outside the range of +/-3d of the current time");
                return(false);
            }

            return(true);
        }
示例#3
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");
            }
        }