예제 #1
0
        private void frequncy_Tick(object sender, ElapsedEventArgs e)
        {
            Log.Information("Start to check the replication status");

            FullJob.Bob();

            Log.Information("Finish to check the replication status");
        }
예제 #2
0
        protected override void OnStart(string[] args)
        {
            strWorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
            System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

            FullJob.Init();

            frequncy          = new Timer();
            frequncy.Interval = FullJob.period * 1000;   //every 30 secs
            frequncy.Elapsed += new System.Timers.ElapsedEventHandler(this.frequncy_Tick);
            frequncy.Enabled  = true;
        }
예제 #3
0
파일: Program.cs 프로젝트: nanoart/repmon
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         //                            .WriteTo.LiterateConsole()
                         .WriteTo.RollingFile(System.AppDomain.CurrentDomain.BaseDirectory + "logs\\repmon-{Date}.txt")
                         .CreateLogger();

            if (args.Length == 0)
            {
//                File.AppendAllText("c:\\temp\\mylog.txt", "Run it as a service");
                // Run your service normally.
                Log.Information("Run it as a service");
                ServiceBase[] ServicesToRun = new ServiceBase[] { new SmartFixService() };
                ServiceBase.Run(ServicesToRun);
            }
            else if (args.Length == 1)
            {
                switch (args[0])
                {
                case "-install":
                    InstallService();
                    StartService();
                    break;

                case "-uninstall":
                    StopService();
                    UninstallService();
                    break;

                case "-normal":
                    FullJob.Init();
                    FullJob.Bob();
                    break;

                case "-testmail":
                    System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
                    FullJob.loadSettings("settings.json");
                    FullJob.notifyDBA(true);
                    Console.WriteLine("Done! check your email inbox or the log file");
                    break;

                default:
                    throw new NotImplementedException();
                }
            }



            //start test

            /*
             *          System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
             *
             *
             *
             *          FullJob.Init();
             *          FullJob.Bob();
             *          var credential = FullJob.getMySQLCredential("server.xml");
             *          FullJob.loadSettings("settings.json");
             *          FullJob.getDaulShieldBinFolder("ALG");
             *          string contents = File.ReadAllText("exout.txt");
             *          FullJob.findErrorCode(contents);
             *                      Console.WriteLine();
             */

            //end test

            /*
             *          ServiceBase[] ServicesToRun;
             *          ServicesToRun = new ServiceBase[]
             *          {
             *              new SmartFixService()
             *          };
             *          ServiceBase.Run(ServicesToRun);
             *
             */
        }
예제 #4
0
        public static void Bob()
        {
            string repOut;

            //check replication status

            repOut = FullJob.getSlaveStatus();
            if (repOut.Length < 10)
            {
                Log.Information("getSlaveStatus probably timeout or no replication configured");
                return;
            }

            if (isIOError(repOut))
            {
                Log.Error("IO error, unfortunately it can't be auto-fixed");
                FullJob.notifyDBA(false);
                return; //we can not fix it
            }

            int nError = findErrorCode(repOut);

            if (nError == 0)
            {
                Log.Information("Replication is healthy");
                return;
            }

            bool bAutoFixed = false;

            int nTry = 0;

            if (nError == 1205)
            {
                FullJob.fix_error_1205();
                nTry       = 1;
                bAutoFixed = true;
            }
            else if (nError == 1032)
            {
                if (isInScope(repOut))
                {
                    int i = 0;
                    do
                    {
                        nTry++;
                        FullJob.fix_error_1032();
                        string repOut2 = FullJob.getSlaveStatus();
                        if (findErrorCode(repOut2) == 0)
                        {
                            bAutoFixed = true;
                        }
                        i++;
                    }while ((i < FullJob.skipMax) && (bAutoFixed == false));
                }
            }

            Log.Information("The actual slave status: {STATUE}", repOut);
            //write log, and notify DBA
            if (bAutoFixed)
            {
                Log.Error("Replication error {Error} fixed with {Try} Tries", nError, nTry);
            }
            else
            {
                Log.Error("Tried {Try} times, Counld not fix the replication error {Error} ", nTry, nError);
            }

            FullJob.notifyDBA(bAutoFixed);
        }