コード例 #1
0
ファイル: BackupThread.cs プロジェクト: mctraveler/MineSharp
        static void BackupThreadRun()
        {
            DateTime nextBackup = DateTime.Now.AddMinutes(30);
            DateTime nextDisk   = DateTime.Now.AddMinutes(5);

            //DateTime nextRestart = DateTime.Now.AddHours (6);
            try
            {
                while (true)
                {
                    //Wait one minute
                    if (Program.Exit.WaitOne(new TimeSpan(0, 1, 0)))
                    {
                        break;
                    }

                    //Watchdog
                    Watchdog.Test();

                    //Every minute we store to disk
                    //MainClass.SendCommand("save-all");

                    //5 minute disk copy
                    if (nextDisk < DateTime.Now)
                    { // || nextBackup < DateTime.Now
                        nextDisk = DateTime.Now.AddMinutes(5);
                        //MainClass.SendCommand ("save-off");
//						MainClass.SendCommand ("tell Player saving to disk");
//						MainClass.SendCommand ("tell nuxas saving to disk");
                        BackendManager.SendCommandAll("save-all");

                        if (Program.Exit.WaitOne(new TimeSpan(0, 0, 5)))
                        {
                            break;
                        }

                        try
                        {
                            string path = "/home/bin/backupDisk";
                            if (File.Exists(path))
                            {
                                Process p = Process.Start(path);
                                p.WaitForExit();
                                Console.WriteLine("BackupDisk done: " + p.ExitCode);
                            }
                        } catch (Exception e)
                        {
                            Console.Error.WriteLine(e.Message);
                        } finally
                        {
                            //MainClass.SendCommand ("save-on");
//							MainClass.SendCommand ("tell Player save done");
//							MainClass.SendCommand ("tell nuxas save done");
                        }
                    }

                    //6h restart

                    /*
                     *                  if (nextRestart < DateTime.Now) {
                     *                          nextRestart = DateTime.Now.AddHours (6);
                     *
                     *                          MainClass.SendCommand ("say Scheduled restart, this will take 20 seconds");
                     *  if (Program.Exit.WaitOne(new TimeSpan(0, 0, 3)))
                     *      break;
                     *
                     *                          MainClass.SendCommand ("save-off");
                     *                          MainClass.SendCommand ("save-all");
                     *
                     *  if (Program.Exit.WaitOne(new TimeSpan(0, 0, 10)))
                     *      break;
                     *
                     *                          MainClass.Kill();
                     *
                     *  if (Program.Exit.WaitOne(new TimeSpan(0, 0, 3)))
                     *      break;
                     *
                     *                          MainClass.SendCommand ("say Now we should be back up and running");
                     *                  }*/

                    //Hourly backups
                    if (nextBackup < DateTime.Now)
                    {
                        try
                        {
                            string path = "/home/bin/backup";
                            if (File.Exists(path))
                            {
                                Process p = Process.Start(path);
                                p.WaitForExit();
                                Console.WriteLine("Backup done " + p.ExitCode);
                            }
                        } catch (Exception e)
                        {
                            Console.Error.WriteLine(e.Message);
                        } finally
                        {
                            nextBackup = DateTime.Now.AddMinutes(60);
                            BackendManager.SendCommandAll("save-on");
                        }
                    }
                }
            } catch (ThreadInterruptedException)
            {
                return;
            }
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: mctraveler/MineSharp
        void ParseCommand(string[] args)
        {
            switch (args [0])
            {
            case "list":
                SendLine(BackendManager.RunningServers());
                return;

            case "shutdown":
                Console.WriteLine("Got Shutdown command");
                SendLine("shutting down");
                Program.Shutdown((args.Length > 1) ? string.Join(" ", args, 1, args.Length - 1) : "Admin initated restart");
                active = false;
                return;

            case "exit":     //Close client connection
                SendLine("bye");
                active = false;
                return;

            case "stop":
                if (args.Length != 2)
                {
                    throw new InvalidArgumentException("Usage: stop <name>");
                }

                Console.WriteLine("Got Suspend command: " + args [1]);
                if (BackendManager.StopServer(args [1]))
                {
                    SendLine("stopped " + args [1]);
                }
                else
                {
                    SendLine("not running " + args [1]);
                }
                return;

            case "start":
                if (args.Length < 2)
                {
                    throw new InvalidArgumentException("Usage: start <name>");
                }

                Console.WriteLine("Got Resume command");
                Server s = BackendManager.StartServer(args [1]);
                SendLine("running\t" + s);
                return;
            }

            if (BlockSaveCommand && args [0].StartsWith("save"))
            {
                return;
            }

            //Vanilla commands
            if (args.Length < 2)
            {
                throw new InvalidArgumentException("Usage: <serverName> command");
            }

            Server server = BackendManager.GetServer(args [0]);

            if (server == null)
            {
                throw new InvalidArgumentException("No such running server: " + args [0]);
            }

            server.SendCommand(string.Join(" ", args, 1, args.Length - 1));
        }
コード例 #3
0
ファイル: Server.cs プロジェクト: mctraveler/MineSharp
        public void Run()
        {
            Log("run");

            while (Program.Exit.WaitOne(0) == false)
            {
                if (exit)
                {
                    Log("exit loop");
                    break;
                }

                Log("Starting: " + psi.FileName + " " + psi.Arguments);
                using (Process p = Process.Start(psi))
                {
                    try
                    {
                        Running.Set();
                        BackendManager.SendToClients(Name + "\tstarted");

                        Console.Error.WriteLine("Minecraft server running");
                        lock (processLock)
                        {
                            process = p;
                        }
                        Log("started");

                        Thread olt = new Thread(OutListener);
                        Thread elt = new Thread(ErrorListener);
                        olt.Start();
                        elt.Start();
                        p.WaitForExit();
                        Log("Exited with code: " + p.ExitCode);
                        olt.Abort();
                        elt.Abort();
                    }
                    catch (Exception e)
                    {
                        Log(e);
                    }
                    finally
                    {
                        lock (processLock)
                        {
                            Kill();
                            process = null;
                        }

                        Running.Reset();
                        try
                        {
                            BackendManager.SendToClients(Name + "\tstopped");
                        }
                        catch (Exception ex)
                        {
                            Log(ex);
                        }
                    }
                    Console.Error.WriteLine("Restarting minecraft");
                }
            }
            shutdown.Set();
        }