Пример #1
0
        /// <summary>
        /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
        /// </summary>
        public BotManager()
        {
            LoginDelay = DefaultLoginDelay;

            Rng            = new Random(Environment.TickCount);
            AssetsReceived = new Dictionary <UUID, bool>();
            RegionsKnown   = new Dictionary <ulong, GridRegion>();

            m_console            = CreateConsole();
            MainConsole.Instance = m_console;

            // Make log4net see the console
            //
            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[]     appenders       = repository.GetAppenders();
            OpenSimAppender consoleAppender = null;

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    consoleAppender         = (OpenSimAppender)appender;
                    consoleAppender.Console = m_console;
                    break;
                }
            }

            m_console.Commands.AddCommand("bot", false, "shutdown",
                                          "shutdown",
                                          "Shutdown bots and exit", HandleShutdown);

            m_console.Commands.AddCommand("bot", false, "quit",
                                          "quit",
                                          "Shutdown bots and exit",
                                          HandleShutdown);

            m_console.Commands.AddCommand("bot", false, "show regions",
                                          "show regions",
                                          "Show regions known to bots",
                                          HandleShowRegions);

            m_console.Commands.AddCommand("bot", false, "show bots",
                                          "show bots",
                                          "Shows the status of all bots",
                                          HandleShowStatus);

//            m_console.Commands.AddCommand("bot", false, "add bots",
//                    "add bots <number>",
//                    "Add more bots", HandleAddBots);

            m_lBot = new List <Bot>();
        }
Пример #2
0
        public void RegisterCommonAppenders(IConfig startupConfig)
        {
            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[] appenders = repository.GetAppenders();

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    m_consoleAppender = (OpenSimAppender)appender;
                }
                else if (appender.Name == "LogFileAppender")
                {
                    m_logFileAppender = (FileAppender)appender;
                }
            }

            if (null == m_consoleAppender)
            {
                Notice("No appender named Console found (see the log4net config file for this executable)!");
            }
            else
            {
                // FIXME: This should be done through an interface rather than casting.
                m_consoleAppender.Console = (ConsoleBase)m_console;

                // If there is no threshold set then the threshold is effectively everything.
                if (null == m_consoleAppender.Threshold)
                {
                    m_consoleAppender.Threshold = Level.All;
                }

                Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
            }

            if (m_logFileAppender != null && startupConfig != null)
            {
                string cfgFileName = startupConfig.GetString("LogFile", null);
                if (cfgFileName != null)
                {
                    m_logFileAppender.File = cfgFileName;
                    m_logFileAppender.ActivateOptions();
                }

                m_log.InfoFormat("[SERVER BASE]: Logging started to file {0}", m_logFileAppender.File);
            }
        }
Пример #3
0
        /// <summary>
        /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
        /// </summary>
        public BotManager()
        {
            m_console            = CreateConsole();
            MainConsole.Instance = m_console;

            // Make log4net see the console
            //
            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[]     appenders       = repository.GetAppenders();
            OpenSimAppender consoleAppender = null;

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    consoleAppender         = (OpenSimAppender)appender;
                    consoleAppender.Console = m_console;
                    break;
                }
            }

            m_console.Commands.AddCommand("bot", false, "shutdown",
                                          "shutdown",
                                          "Gracefully shut down bots", HandleShutdown);

            m_console.Commands.AddCommand("bot", false, "quit",
                                          "quit",
                                          "Force quit (DANGEROUS, try shutdown first)",
                                          HandleShutdown);

            m_console.Commands.AddCommand("bot", false, "add bots",
                                          "add bots <number>",
                                          "Add more bots", HandleAddBots);

            m_lBot = new List <PhysicsBot>();
        }
Пример #4
0
        /// <summary>
        /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
        /// </summary>
        public BotManager()
        {
            // We set this to avoid issues with bots running out of HTTP connections if many are run from a single machine
            // to multiple regions.
            Settings.MAX_HTTP_CONNECTIONS = int.MaxValue;

//            System.Threading.ThreadPool.SetMaxThreads(600, 240);
//
//            int workerThreads, iocpThreads;
//            System.Threading.ThreadPool.GetMaxThreads(out workerThreads, out iocpThreads);
//            Console.WriteLine("ThreadPool.GetMaxThreads {0} {1}", workerThreads, iocpThreads);

            InitBotSendAgentUpdates      = true;
            InitBotRequestObjectTextures = true;

            LoginDelay = DefaultLoginDelay;

            Rng            = new Random(Environment.TickCount);
            AssetsReceived = new Dictionary <UUID, bool>();
            RegionsKnown   = new Dictionary <ulong, GridRegion>();

            m_console            = CreateConsole();
            MainConsole.Instance = m_console;

            // Make log4net see the console
            //
            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[]     appenders       = repository.GetAppenders();
            OpenSimAppender consoleAppender = null;

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    consoleAppender         = (OpenSimAppender)appender;
                    consoleAppender.Console = m_console;
                    break;
                }
            }

            m_console.Commands.AddCommand(
                "Bots", false, "shutdown", "shutdown", "Shutdown bots and exit", HandleShutdown);

            m_console.Commands.AddCommand(
                "Bots", false, "quit", "quit", "Shutdown bots and exit", HandleShutdown);

            m_console.Commands.AddCommand(
                "Bots", false, "connect", "connect [<n>]", "Connect bots",
                "If an <n> is given, then the first <n> disconnected bots by postfix number are connected.\n"
                + "If no <n> is given, then all currently disconnected bots are connected.",
                HandleConnect);

            m_console.Commands.AddCommand(
                "Bots", false, "disconnect", "disconnect [<n>]", "Disconnect bots",
                "Disconnecting bots will interupt any bot connection process, including connection on startup.\n"
                + "If an <n> is given, then the last <n> connected bots by postfix number are disconnected.\n"
                + "If no <n> is given, then all currently connected bots are disconnected.",
                HandleDisconnect);

            m_console.Commands.AddCommand(
                "Bots", false, "add behaviour", "add behaviour <abbreviated-name> [<bot-number>]",
                "Add a behaviour to a bot",
                "If no bot number is specified then behaviour is added to all bots.\n"
                + "Can be performed on connected or disconnected bots.",
                HandleAddBehaviour);

            m_console.Commands.AddCommand(
                "Bots", false, "remove behaviour", "remove behaviour <abbreviated-name> [<bot-number>]",
                "Remove a behaviour from a bot",
                "If no bot number is specified then behaviour is added to all bots.\n"
                + "Can be performed on connected or disconnected bots.",
                HandleRemoveBehaviour);

            m_console.Commands.AddCommand(
                "Bots", false, "sit", "sit", "Sit all bots on the ground.",
                HandleSit);

            m_console.Commands.AddCommand(
                "Bots", false, "stand", "stand", "Stand all bots.",
                HandleStand);

            m_console.Commands.AddCommand(
                "Bots", false, "set bots", "set bots <key> <value>", "Set a setting for all bots.", HandleSetBots);

            m_console.Commands.AddCommand(
                "Bots", false, "show regions", "show regions", "Show regions known to bots", HandleShowRegions);

            m_console.Commands.AddCommand(
                "Bots", false, "show bots", "show bots", "Shows the status of all bots.", HandleShowBotsStatus);

            m_console.Commands.AddCommand(
                "Bots", false, "show bot", "show bot <bot-number>",
                "Shows the detailed status and settings of a particular bot.", HandleShowBotStatus);

            m_console.Commands.AddCommand(
                "Debug",
                false,
                "debug lludp packet",
                "debug lludp packet <level> <avatar-first-name> <avatar-last-name>",
                "Turn on received packet logging.",
                "If level >  0 then all received packets that are not duplicates are logged.\n"
                + "If level <= 0 then no received packets are logged.",
                HandleDebugLludpPacketCommand);

            m_console.Commands.AddCommand(
                "Bots", false, "show status", "show status", "Shows pCampbot status.", HandleShowStatus);

            m_bots = new List <Bot>();

            Watchdog.Enabled = true;
            StatsManager.RegisterConsoleCommands(m_console);

            m_serverStatsCollector = new ServerStatsCollector();
            m_serverStatsCollector.Initialise(null);
            m_serverStatsCollector.Enabled = true;
            m_serverStatsCollector.Start();

            BotConnectingState = BotManagerBotConnectingState.Ready;
        }
Пример #5
0
        /// <summary>
        /// Must be overriden by child classes for their own server specific startup behaviour.
        /// </summary>
        protected virtual void StartupSpecific()
        {
            if (m_console != null)
            {
                ILoggerRepository repository = LogManager.GetRepository();
                IAppender[]       appenders  = repository.GetAppenders();

                foreach (IAppender appender in appenders)
                {
                    if (appender.Name == "Console")
                    {
                        m_consoleAppender = (OpenSimAppender)appender;
                        break;
                    }
                }

                if (null == m_consoleAppender)
                {
                    Notice("No appender named Console found (see the log4net config file for this executable)!");
                }
                else
                {
                    m_consoleAppender.Console = m_console;

                    // If there is no threshold set then the threshold is effectively everything.
                    if (null == m_consoleAppender.Threshold)
                    {
                        m_consoleAppender.Threshold = Level.All;
                    }

                    Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
                }

                m_console.Commands.AddCommand("General", false, "quit",
                                              "quit",
                                              "Quit the application", HandleQuit);

                m_console.Commands.AddCommand("General", false, "shutdown",
                                              "shutdown",
                                              "Quit the application", HandleQuit);

                m_console.Commands.AddCommand("General", false, "set log level",
                                              "set log level <level>",
                                              "Set the console logging level", HandleLogLevel);

                m_console.Commands.AddCommand("General", false, "show info",
                                              "show info",
                                              "Show general information about the server", HandleShow);

                m_console.Commands.AddCommand("General", false, "show stats",
                                              "show stats",
                                              "Show statistics", HandleShow);

                m_console.Commands.AddCommand("General", false, "show threads",
                                              "show threads",
                                              "Show thread status", HandleShow);

                m_console.Commands.AddCommand("General", false, "show uptime",
                                              "show uptime",
                                              "Show server uptime", HandleShow);

                m_console.Commands.AddCommand("General", false, "show version",
                                              "show version",
                                              "Show server version", HandleShow);

                m_console.Commands.AddCommand("General", false, "threads abort",
                                              "threads abort <thread-id>",
                                              "Abort a managed thread.  Use \"show threads\" to find possible threads.", HandleThreadsAbort);

                m_console.Commands.AddCommand("General", false, "threads show",
                                              "threads show",
                                              "Show thread status.  Synonym for \"show threads\"",
                                              (string module, string[] args) => Notice(GetThreadsReport()));
            }
        }
Пример #6
0
        private void SetUpConsole()
        {
            List<ICommandConsole> Plugins = AuroraModuleLoader.PickupModules<ICommandConsole>();
            foreach (ICommandConsole plugin in Plugins)
            {
                plugin.Initialize("Region", ConfigSource, this);
            }

            m_console = m_applicationRegistry.Get<ICommandConsole>();
            if (m_console == null)
                m_console = new LocalConsole();
            ILoggerRepository repository = LogManager.GetRepository();
            IAppender[] appenders = repository.GetAppenders();
            OpenSimAppender m_consoleAppender = null;
            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    m_consoleAppender = (OpenSimAppender)appender;
                    break;
                }
            }

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "LogFileAppender")
                {
                    m_logFileAppender = appender;
                }
            }

            if (null != m_consoleAppender)
            {
                m_consoleAppender.Console = m_console;
                // If there is no threshold set then the threshold is effectively everything.
                if (null == m_consoleAppender.Threshold)
                    m_consoleAppender.Threshold = Level.All;
                m_console.Output(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
            }
            if (m_console == null)
                m_console = new LocalConsole();
            MainConsole.Instance = m_console;
        }
Пример #7
0
        // Handle all the automagical stuff
        //
        public ServicesServerBase(string prompt, string[] args)
        {
            // Save raw arguments
            //
            m_Arguments = args;

            // Read command line
            //
            ArgvConfigSource argvConfig = new ArgvConfigSource(args);

            argvConfig.AddSwitch("Startup", "console", "c");
            argvConfig.AddSwitch("Startup", "logfile", "l");
            argvConfig.AddSwitch("Startup", "inifile", "i");
            argvConfig.AddSwitch("Startup", "prompt", "p");
            argvConfig.AddSwitch("Startup", "logconfig", "g");

            // Automagically create the ini file name
            //
            string fileName  = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location);
            string iniFile   = fileName + ".ini";
            string logConfig = null;

            IConfig startupConfig = argvConfig.Configs["Startup"];

            if (startupConfig != null)
            {
                // Check if a file name was given on the command line
                //
                iniFile = startupConfig.GetString("inifile", iniFile);
                //
                // Check if a prompt was given on the command line
                prompt = startupConfig.GetString("prompt", prompt);
                //
                // Check for a Log4Net config file on the command line
                logConfig = startupConfig.GetString("logconfig", logConfig);
            }

            // Find out of the file name is a URI and remote load it
            // if it's possible. Load it as a local file otherwise.
            //
            Uri configUri;

            try
            {
                if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) &&
                    configUri.Scheme == Uri.UriSchemeHttp)
                {
                    XmlReader r = XmlReader.Create(iniFile);
                    m_Config = new XmlConfigSource(r);
                }
                else
                {
                    m_Config = new IniConfigSource(iniFile);
                }
            }
            catch (Exception)
            {
                System.Console.WriteLine("Error reading from config source {0}",
                                         iniFile);
                Thread.CurrentThread.Abort();
            }

            // Merge the configuration from the command line into the
            // loaded file
            //
            m_Config.Merge(argvConfig);

            // Refresh the startupConfig post merge
            //
            if (m_Config.Configs["Startup"] != null)
            {
                startupConfig = m_Config.Configs["Startup"];
            }

            prompt = startupConfig.GetString("Prompt", prompt);

            // Allow derived classes to load config before the console is
            // opened.
            //
            ReadConfig();

            // Create main console
            //
            string consoleType = "local";

            if (startupConfig != null)
            {
                consoleType = startupConfig.GetString("console", consoleType);
            }

            if (consoleType == "basic")
            {
                MainConsole.Instance = new CommandConsole(prompt);
            }
            else if (consoleType == "rest")
            {
                MainConsole.Instance = new RemoteConsole(prompt);
                ((RemoteConsole)MainConsole.Instance).ReadConfig(Config);
            }
            else
            {
                MainConsole.Instance = new LocalConsole(prompt);
            }

            // Configure the appenders for log4net
            //
            OpenSimAppender consoleAppender = null;
            FileAppender    fileAppender    = null;

            if (logConfig != null)
            {
                FileInfo cfg = new FileInfo(logConfig);
                XmlConfigurator.Configure(cfg);
            }
            else
            {
                XmlConfigurator.Configure();
            }

            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[] appenders = repository.GetAppenders();

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    consoleAppender = (OpenSimAppender)appender;
                }
                if (appender.Name == "LogFileAppender")
                {
                    fileAppender = (FileAppender)appender;
                }
            }

            if (consoleAppender == null)
            {
                System.Console.WriteLine("No console appender found. Server can't start");
                Thread.CurrentThread.Abort();
            }
            else
            {
                consoleAppender.Console = MainConsole.Instance;

                if (null == consoleAppender.Threshold)
                {
                    consoleAppender.Threshold = Level.All;
                }
            }

            // Set log file
            //
            if (fileAppender != null)
            {
                if (startupConfig != null)
                {
                    string cfgFileName = startupConfig.GetString("logfile", null);
                    if (cfgFileName != null)
                    {
                        fileAppender.File = cfgFileName;
                        fileAppender.ActivateOptions();
                    }
                }
            }

            if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty)
            {
                CreatePIDFile(startupConfig.GetString("PIDFile"));
            }

            // Register the quit command
            //
            MainConsole.Instance.Commands.AddCommand("base", false, "quit",
                                                     "quit",
                                                     "Quit the application", HandleQuit);

            MainConsole.Instance.Commands.AddCommand("base", false, "shutdown",
                                                     "shutdown",
                                                     "Quit the application", HandleQuit);

            // Register a command to read other commands from a file
            MainConsole.Instance.Commands.AddCommand("base", false, "command-script",
                                                     "command-script <script>",
                                                     "Run a command script from file", HandleScript);


            // Allow derived classes to perform initialization that
            // needs to be done after the console has opened
            //
            Initialise();
        }
Пример #8
0
        /// <summary>
        /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
        /// </summary>
        public BotManager()
        {
            InitBotSendAgentUpdates      = true;
            InitBotRequestObjectTextures = true;

            LoginDelay = DefaultLoginDelay;

            Rng            = new Random(Environment.TickCount);
            AssetsReceived = new Dictionary <UUID, bool>();
            RegionsKnown   = new Dictionary <ulong, GridRegion>();

            m_console            = CreateConsole();
            MainConsole.Instance = m_console;

            // Make log4net see the console
            //
            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[]     appenders       = repository.GetAppenders();
            OpenSimAppender consoleAppender = null;

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    consoleAppender         = (OpenSimAppender)appender;
                    consoleAppender.Console = m_console;
                    break;
                }
            }

            m_console.Commands.AddCommand(
                "bot", false, "shutdown", "shutdown", "Shutdown bots and exit", HandleShutdown);

            m_console.Commands.AddCommand(
                "bot", false, "quit", "quit", "Shutdown bots and exit", HandleShutdown);

            m_console.Commands.AddCommand(
                "bot", false, "connect", "connect [<n>]", "Connect bots",
                "If an <n> is given, then the first <n> disconnected bots by postfix number are connected.\n"
                + "If no <n> is given, then all currently disconnected bots are connected.",
                HandleConnect);

            m_console.Commands.AddCommand(
                "bot", false, "disconnect", "disconnect [<n>]", "Disconnect bots",
                "Disconnecting bots will interupt any bot connection process, including connection on startup.\n"
                + "If an <n> is given, then the last <n> connected bots by postfix number are disconnected.\n"
                + "If no <n> is given, then all currently connected bots are disconnected.",
                HandleDisconnect);

            m_console.Commands.AddCommand(
                "bot", false, "add behaviour", "add behaviour <abbreviated-name> [<bot-number>]",
                "Add a behaviour to a bot",
                "If no bot number is specified then behaviour is added to all bots.\n"
                + "Can be performed on connected or disconnected bots.",
                HandleAddBehaviour);

            m_console.Commands.AddCommand(
                "bot", false, "remove behaviour", "remove behaviour <abbreviated-name> [<bot-number>]",
                "Remove a behaviour from a bot",
                "If no bot number is specified then behaviour is added to all bots.\n"
                + "Can be performed on connected or disconnected bots.",
                HandleRemoveBehaviour);

            m_console.Commands.AddCommand(
                "bot", false, "sit", "sit", "Sit all bots on the ground.",
                HandleSit);

            m_console.Commands.AddCommand(
                "bot", false, "stand", "stand", "Stand all bots.",
                HandleStand);

            m_console.Commands.AddCommand(
                "bot", false, "set bots", "set bots <key> <value>", "Set a setting for all bots.", HandleSetBots);

            m_console.Commands.AddCommand(
                "bot", false, "show regions", "show regions", "Show regions known to bots", HandleShowRegions);

            m_console.Commands.AddCommand(
                "bot", false, "show bots", "show bots", "Shows the status of all bots", HandleShowBotsStatus);

            m_console.Commands.AddCommand(
                "bot", false, "show bot", "show bot <bot-number>",
                "Shows the detailed status and settings of a particular bot.", HandleShowBotStatus);

            m_bots = new List <Bot>();
        }
Пример #9
0
        /// <summary>
        /// Must be overriden by child classes for their own server specific startup behaviour.
        /// </summary>
        protected virtual void StartupSpecific()
        {
            if (m_console != null)
            {
                ILoggerRepository repository = LogManager.GetRepository();
                IAppender[] appenders = repository.GetAppenders();

                foreach (IAppender appender in appenders)
                {
                    if (appender.Name == "Console")
                    {
                        m_consoleAppender = (OpenSimAppender)appender;
                        break;
                    }
                }

                if (null == m_consoleAppender)
                {
                    Notice("No appender named Console found (see the log4net config file for this executable)!");
                }
                else
                {
                    m_consoleAppender.Console = m_console;
                    
                    // If there is no threshold set then the threshold is effectively everything.
                    if (null == m_consoleAppender.Threshold)
                        m_consoleAppender.Threshold = Level.All;
                    
                    Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
                }
                
                m_console.Commands.AddCommand("base", false, "quit",
                        "quit",
                        "Quit the application", HandleQuit);

                m_console.Commands.AddCommand("base", false, "shutdown",
                        "shutdown",
                        "Quit the application", HandleQuit);

                m_console.Commands.AddCommand("base", false, "set log level",
                        "set log level <level>",
                        "Set the console logging level", HandleLogLevel);

                m_console.Commands.AddCommand("base", false, "show info",
                        "show info",
                        "Show general information about the server", HandleShow);

                m_console.Commands.AddCommand("base", false, "show stats",
                        "show stats",
                        "Show statistics", HandleShow);

                m_console.Commands.AddCommand("base", false, "show threads",
                        "show threads",
                        "Show thread status", HandleShow);

                m_console.Commands.AddCommand("base", false, "show uptime",
                        "show uptime",
                        "Show server uptime", HandleShow);

                m_console.Commands.AddCommand("base", false, "show version",
                        "show version",
                        "Show server version", HandleShow);

                m_console.Commands.AddCommand("base", false, "threads abort",
                        "threads abort <thread-id>",
                        "Abort a managed thread.  Use \"show threads\" to find possible threads.", HandleThreadsAbort);

                m_console.Commands.AddCommand("base", false, "threads show",
                        "threads show",
                        "Show thread status.  Synonym for \"show threads\"",
                        (string module, string[] args) => Notice(GetThreadsReport()));
            }
        }
Пример #10
0
        /// <summary>
        /// Find the console plugin and initialize the logger for it
        /// </summary>
        public virtual void SetUpConsole()
        {
            List <ICommandConsole> Plugins = AuroraModuleLoader.PickupModules <ICommandConsole>();

            foreach (ICommandConsole plugin in Plugins)
            {
                plugin.Initialize("Region", ConfigSource, this);
            }

            m_console = m_applicationRegistry.RequestModuleInterface <ICommandConsole>();
            if (m_console == null)
            {
                m_console = new LocalConsole();
            }
            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[] appenders = repository.GetAppenders();
            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    m_consoleAppender = (OpenSimAppender)appender;
                    break;
                }
            }

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "LogFileAppender")
                {
                    m_logFileAppender = appender;
                }
            }

            if (null != m_consoleAppender)
            {
                m_consoleAppender.Console = m_console;
                // If there is no threshold set then the threshold is effectively everything.
                if (null == m_consoleAppender.Threshold)
                {
                    m_consoleAppender.Threshold = Level.All;
                }
                repository.Threshold = m_consoleAppender.Threshold;
                foreach (ILogger log in repository.GetCurrentLoggers())
                {
                    log.Level = m_consoleAppender.Threshold;
                }
                m_log.Fatal(String.Format("[Console]: Console log level is {0}", m_consoleAppender.Threshold));
            }

            IConfig startupConfig = m_config.Configs["Startup"];

            if (m_logFileAppender != null)
            {
                if (m_logFileAppender is log4net.Appender.FileAppender)
                {
                    log4net.Appender.FileAppender appender = (log4net.Appender.FileAppender)m_logFileAppender;
                    string fileName = startupConfig.GetString("LogFile", String.Empty);
                    if (fileName != String.Empty)
                    {
                        appender.File = fileName;
                        appender.ActivateOptions();
                    }
                }
            }

            MainConsole.Instance = m_console;
        }
Пример #11
0
        /// <summary>
        /// Find the console plugin and initialize the logger for it
        /// </summary>
        public virtual void SetUpConsole()
        {
            List<ICommandConsole> Plugins = AuroraModuleLoader.PickupModules<ICommandConsole>();
            foreach (ICommandConsole plugin in Plugins)
            {
                plugin.Initialize("Region", ConfigSource, this);
            }

            m_console = m_applicationRegistry.RequestModuleInterface<ICommandConsole>();
            if (m_console == null)
                m_console = new LocalConsole();
            ILoggerRepository repository = LogManager.GetRepository();
            IAppender[] appenders = repository.GetAppenders();
            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    m_consoleAppender = (OpenSimAppender)appender;
                    break;
                }
            }

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "LogFileAppender")
                {
                    m_logFileAppender = appender;
                }
            }

            if (null != m_consoleAppender)
            {
                m_consoleAppender.Console = m_console;
                // If there is no threshold set then the threshold is effectively everything.
                if (null == m_consoleAppender.Threshold)
                    m_consoleAppender.Threshold = Level.All;
                m_log.Fatal (String.Format ("[Console]: Console log level is {0}", m_consoleAppender.Threshold));
            }

            IConfig startupConfig = m_config.Configs["Startup"];
            if (m_logFileAppender != null)
            {
                if (m_logFileAppender is log4net.Appender.FileAppender)
                {
                    log4net.Appender.FileAppender appender = (log4net.Appender.FileAppender)m_logFileAppender;
                    string fileName = startupConfig.GetString("LogFile", String.Empty);
                    if (fileName != String.Empty)
                    {
                        appender.File = fileName;
                        appender.ActivateOptions();
                    }
                }
            }

            MainConsole.Instance = m_console;
        }
Пример #12
0
        // Handle all the automagical stuff
        //
        public ServicesServerBase(string prompt, string[] args) : base()
        {
            // Save raw arguments
            //
            m_Arguments = args;

            // Read command line
            //
            ArgvConfigSource argvConfig = new ArgvConfigSource(args);

            argvConfig.AddSwitch("Startup", "console", "c");
            argvConfig.AddSwitch("Startup", "logfile", "l");
            argvConfig.AddSwitch("Startup", "inifile", "i");
            argvConfig.AddSwitch("Startup", "prompt", "p");
            argvConfig.AddSwitch("Startup", "logconfig", "g");

            // Automagically create the ini file name
            //
            string fileName  = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location);
            string iniFile   = fileName + ".ini";
            string logConfig = null;

            IConfig startupConfig = argvConfig.Configs["Startup"];

            if (startupConfig != null)
            {
                // Check if a file name was given on the command line
                //
                iniFile = startupConfig.GetString("inifile", iniFile);
                //
                // Check if a prompt was given on the command line
                prompt = startupConfig.GetString("prompt", prompt);
                //
                // Check for a Log4Net config file on the command line
                logConfig = startupConfig.GetString("logconfig", logConfig);
            }

            // Find out of the file name is a URI and remote load it
            // if it's possible. Load it as a local file otherwise.
            //
            Uri configUri;

            try
            {
                if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) &&
                    configUri.Scheme == Uri.UriSchemeHttp)
                {
                    XmlReader r = XmlReader.Create(iniFile);
                    Config = new XmlConfigSource(r);
                }
                else
                {
                    Config = new IniConfigSource(iniFile);
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Error reading from config source.  {0}", e.Message);
                Environment.Exit(1);
            }

            // Merge the configuration from the command line into the
            // loaded file
            //
            Config.Merge(argvConfig);

            // Refresh the startupConfig post merge
            //
            if (Config.Configs["Startup"] != null)
            {
                startupConfig = Config.Configs["Startup"];
            }

            ConfigDirectory = startupConfig.GetString("ConfigDirectory", ".");

            prompt = startupConfig.GetString("Prompt", prompt);

            // Allow derived classes to load config before the console is
            // opened.
            //
            ReadConfig();

            // Create main console
            //
            string consoleType = "local";

            if (startupConfig != null)
            {
                consoleType = startupConfig.GetString("console", consoleType);
            }

            if (consoleType == "basic")
            {
                MainConsole.Instance = new CommandConsole(prompt);
            }
            else if (consoleType == "rest")
            {
                MainConsole.Instance = new RemoteConsole(prompt);
                ((RemoteConsole)MainConsole.Instance).ReadConfig(Config);
            }
            else
            {
                MainConsole.Instance = new LocalConsole(prompt);
            }

            m_console = MainConsole.Instance;

            // Configure the appenders for log4net
            //
            OpenSimAppender consoleAppender = null;
            FileAppender    fileAppender    = null;

            if (logConfig != null)
            {
                FileInfo cfg = new FileInfo(logConfig);
                XmlConfigurator.Configure(cfg);
            }
            else
            {
                XmlConfigurator.Configure();
            }

            RegisterCommonAppenders(startupConfig);

            if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty)
            {
                CreatePIDFile(startupConfig.GetString("PIDFile"));
            }

            RegisterCommonCommands();

            // Register the quit command
            //
            MainConsole.Instance.Commands.AddCommand("General", false, "quit",
                                                     "quit",
                                                     "Quit the application", HandleQuit);

            MainConsole.Instance.Commands.AddCommand("General", false, "shutdown",
                                                     "shutdown",
                                                     "Quit the application", HandleQuit);

            // Allow derived classes to perform initialization that
            // needs to be done after the console has opened
            //
            Initialise();
        }
Пример #13
0
        /// <summary>
        /// Performs startup specific to the region server, including initialization of the scene 
        /// such as loading configuration from disk.
        /// </summary>
        protected virtual void StartupSpecific()
        {
            #region Console Setup

            if (m_console != null)
            {
                ILoggerRepository repository = LogManager.GetRepository();
                IAppender[] appenders = repository.GetAppenders();

                foreach (IAppender appender in appenders)
                {
                    if (appender.Name == "Console")
                    {
                        m_consoleAppender = (OpenSimAppender)appender;
                        break;
                    }
                }

                if (null == m_consoleAppender)
                {
                    Notice("No appender named Console found (see the log4net config file for this executable)!");
                }
                else
                {
                    m_consoleAppender.Console = m_console;

                    // If there is no threshold set then the threshold is effectively everything.
                    if (null == m_consoleAppender.Threshold)
                        m_consoleAppender.Threshold = Level.All;

                    Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
                }

                m_console.Commands.AddCommand("base", false, "quit",
                        "quit",
                        "Quit the application", HandleQuit);

                m_console.Commands.AddCommand("base", false, "shutdown",
                        "shutdown",
                        "Quit the application", HandleQuit);

                m_console.Commands.AddCommand("base", false, "set log level",
                        "set log level <level>",
                        "Set the console logging level", HandleLogLevel);

                m_console.Commands.AddCommand("base", false, "show info",
                        "show info",
                        "Show general information", HandleShow);

                m_console.Commands.AddCommand("base", false, "show stats",
                        "show stats",
                        "Show statistics", HandleShow);

                m_console.Commands.AddCommand("base", false, "show threads",
                        "show threads",
                        "Show thread status", HandleShow);

                m_console.Commands.AddCommand("base", false, "show uptime",
                        "show uptime",
                        "Show server uptime", HandleShow);

                m_console.Commands.AddCommand("base", false, "show version",
                        "show version",
                        "Show server version", HandleShow);
            }

            #endregion Console Setup

            IConfig startupConfig = m_config.Source.Configs["Startup"];
            if (startupConfig != null)
            {
                string pidFile = startupConfig.GetString("PIDFile", String.Empty);
                if (pidFile != String.Empty)
                    CreatePIDFile(pidFile);
                
                userStatsURI = startupConfig.GetString("Stats_URI", String.Empty);
            }

            // Load the simulation data service
            IConfig simDataConfig = m_config.Source.Configs["SimulationDataStore"];
            if (simDataConfig == null)
                throw new Exception("Configuration file is missing the [SimulationDataStore] section");
            string module = simDataConfig.GetString("LocalServiceModule", String.Empty);
            if (String.IsNullOrEmpty(module))
                throw new Exception("Configuration file is missing the LocalServiceModule parameter in the [SimulationDataStore] section");
            m_simulationDataService = ServerUtils.LoadPlugin<ISimulationDataService>(module, new object[] { m_config.Source });

            // Load the estate data service
            IConfig estateDataConfig = m_config.Source.Configs["EstateDataStore"];
            if (estateDataConfig == null)
                throw new Exception("Configuration file is missing the [EstateDataStore] section");
            module = estateDataConfig.GetString("LocalServiceModule", String.Empty);
            if (String.IsNullOrEmpty(module))
                throw new Exception("Configuration file is missing the LocalServiceModule parameter in the [EstateDataStore] section");
            m_estateDataService = ServerUtils.LoadPlugin<IEstateDataService>(module, new object[] { m_config.Source });

            m_stats = StatsManager.StartCollectingSimExtraStats();

            // Create a ModuleLoader instance
            m_moduleLoader = new ModuleLoader(m_config.Source);

            LoadApplicationPlugins();
            foreach (IApplicationPlugin plugin in m_appPlugins)
                plugin.Initialise(this);
            foreach (IApplicationPlugin plugin in m_appPlugins)
                plugin.PostInitialise();

            AddPluginCommands();
        }
Пример #14
0
        private void SetUpConsole(IConfigSource config, IRegistryCore registry)
        {
            List <ICommandConsole> Plugins = AuroraModuleLoader.PickupModules <ICommandConsole>();

            foreach (ICommandConsole plugin in Plugins)
            {
                plugin.Initialize(config, registry.RequestModuleInterface <ISimulationBase>());
            }

            List <INotificationService> NotificationPlugins = AuroraModuleLoader.PickupModules <INotificationService>();

            foreach (INotificationService plugin in NotificationPlugins)
            {
                plugin.Init(config, registry);
            }

            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[] appenders = repository.GetAppenders();
            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    m_consoleAppender = (OpenSimAppender)appender;
                    break;
                }
            }

            if (null != m_consoleAppender)
            {
                m_consoleAppender.Console = MainConsole.Instance;
                // If there is no threshold set then the threshold is effectively everything.
                if (null == m_consoleAppender.Threshold)
                {
                    m_consoleAppender.Threshold = Level.All;
                }
                repository.Threshold = m_consoleAppender.Threshold;
                foreach (ILogger log in repository.GetCurrentLoggers())
                {
                    log.Level = m_consoleAppender.Threshold;
                }
            }
            IAppender logFileAppender = null;

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "LogFileAppender")
                {
                    logFileAppender = appender;
                }
            }

            if (logFileAppender != null)
            {
                if (logFileAppender is FileAppender)
                {
                    FileAppender appender      = (FileAppender)logFileAppender;
                    IConfig      startupConfig = config.Configs["Startup"];
                    string       fileName      = startupConfig.GetString("LogFile", String.Empty);
                    if (fileName != String.Empty)
                    {
                        appender.File = fileName;
                        appender.ActivateOptions();
                    }
                }
            }
            if (MainConsole.Instance == null)
            {
                m_log.Info("[Console]: No Console located");
                return;
            }

            MainConsole.Instance.MaxLogLevel = m_consoleAppender.Threshold;
            if (m_consoleAppender != null)
            {
                MainConsole.Instance.Fatal(String.Format("[Console]: Console log level is {0}", m_consoleAppender.Threshold));
            }

            MainConsole.Instance.Commands.AddCommand("set log level", "set log level [level]", "Set the console logging level", HandleLogLevel);

            MainConsole.Instance.Commands.AddCommand("get log level", "get log level", "Returns the current console logging level", HandleGetLogLevel);
        }
Пример #15
0
        private void SetUpConsole(IConfigSource config, IRegistryCore registry)
        {
            List<ICommandConsole> Plugins = AuroraModuleLoader.PickupModules<ICommandConsole>();
            foreach (ICommandConsole plugin in Plugins)
            {
                plugin.Initialize(config, registry.RequestModuleInterface<ISimulationBase>());
            }

            List<INotificationService> NotificationPlugins = AuroraModuleLoader.PickupModules<INotificationService>();
            foreach (INotificationService plugin in NotificationPlugins)
            {
                plugin.Init(config, registry);
            }

            ILoggerRepository repository = LogManager.GetRepository();
            IAppender[] appenders = repository.GetAppenders();
            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    m_consoleAppender = (OpenSimAppender)appender;
                    break;
                }
            }

            if (null != m_consoleAppender)
            {
                m_consoleAppender.Console = MainConsole.Instance;
                // If there is no threshold set then the threshold is effectively everything.
                if (null == m_consoleAppender.Threshold)
                    m_consoleAppender.Threshold = Level.All;
                repository.Threshold = m_consoleAppender.Threshold;
                foreach (ILogger log in repository.GetCurrentLoggers())
                {
                    log.Level = m_consoleAppender.Threshold;
                }
            }
            IAppender logFileAppender = null;
            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "LogFileAppender")
                {
                    logFileAppender = appender;
                }
            }

            if (logFileAppender != null)
            {
                if (logFileAppender is FileAppender)
                {
                    FileAppender appender = (FileAppender)logFileAppender;
                    IConfig startupConfig = config.Configs["Startup"];
                    string fileName = startupConfig.GetString("LogFile", String.Empty);
                    if (fileName != String.Empty)
                    {
                        appender.File = fileName;
                        appender.ActivateOptions();
                    }
                }
            }
            if (MainConsole.Instance == null)
            {
                m_log.Info("[Console]: No Console located");
                return;
            }

            if (m_consoleAppender != null)
                MainConsole.Instance.Fatal(String.Format("[Console]: Console log level is {0}", m_consoleAppender.Threshold));

            MainConsole.Instance.Commands.AddCommand("set log level", "set log level [level]", "Set the console logging level", HandleLogLevel);
        }
Пример #16
0
        /// <summary>
        /// Must be overriden by child classes for their own server specific startup behaviour.
        /// </summary>
        protected virtual void StartupSpecific()
        {
            if (m_console != null)
            {
                ILoggerRepository repository = LogManager.GetRepository();
                IAppender[]       appenders  = repository.GetAppenders();

                foreach (IAppender appender in appenders)
                {
                    if (appender.Name == "Console")
                    {
                        m_consoleAppender = (OpenSimAppender)appender;
                        break;
                    }
                }

                if (null == m_consoleAppender)
                {
                    Notice("No appender named Console found (see the log4net config file for this executable)!");
                }
                else
                {
                    m_consoleAppender.Console = m_console;

                    // If there is no threshold set then the threshold is effectively everything.
                    if (null == m_consoleAppender.Threshold)
                    {
                        m_consoleAppender.Threshold = Level.All;
                    }

                    Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
                }

                m_console.Commands.AddCommand("base", false, "quit",
                                              "quit",
                                              "Quit the application", HandleQuit);

                m_console.Commands.AddCommand("base", false, "shutdown",
                                              "shutdown",
                                              "Quit the application", HandleQuit);

                m_console.Commands.AddCommand("base", false, "forcegc",
                                              "forcegc",
                                              "Forces an immediate full garbage collection (testing/dev only)", HandleForceGC);

                m_console.Commands.AddCommand("base", false, "set log level",
                                              "set log level <level>",
                                              "Set the console logging level", HandleLogLevel);

                m_console.Commands.AddCommand("base", false, "show info",
                                              "show info",
                                              "Show general information", HandleShow);

                m_console.Commands.AddCommand("base", false, "show stats",
                                              "show stats",
                                              "Show statistics", HandleShow);

                m_console.Commands.AddCommand("base", false, "show threads",
                                              "show threads",
                                              "Show thread status", HandleShow);

                m_console.Commands.AddCommand("base", false, "show uptime",
                                              "show uptime",
                                              "Show server uptime", HandleShow);

                m_console.Commands.AddCommand("base", false, "show version",
                                              "show version",
                                              "Show server version", HandleShow);
            }
        }
Пример #17
0
        // Handle all the automagical stuff
        public ServicesServerBase(string prompt, string[] args)
        {
            // Save raw arguments
            m_Arguments = args;

            // Read command line
            ArgvConfigSource argvConfig = new ArgvConfigSource(args);

            argvConfig.AddSwitch("Startup", "console", "c");
            argvConfig.AddSwitch("Startup", "logfile", "l");
            argvConfig.AddSwitch("Startup", "inifile", "i");

            // Automagically create the ini file name
            string       fullName     = Assembly.GetEntryAssembly().FullName;
            AssemblyName assemblyName = new AssemblyName(fullName);

            string iniFile = assemblyName.Name + ".ini";

            // Check if a file name was given on the command line
            IConfig startupConfig = argvConfig.Configs["Startup"];

            if (startupConfig != null)
            {
                iniFile = startupConfig.GetString("inifile", iniFile);
            }

            // Find out of the file name is a URI and remote load it
            // if it's possible. Load it as a local file otherwise.
            Uri configUri;

            try
            {
                if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) && configUri.Scheme == Uri.UriSchemeHttp)
                {
                    XmlReader r = XmlReader.Create(iniFile);
                    m_Config = new XmlConfigSource(r);
                }
                else
                {
                    m_Config = new IniConfigSource(iniFile);
                }
            }
            catch (Exception)
            {
                System.Console.WriteLine("Error reading from config source {0}", iniFile);
                Thread.CurrentThread.Abort();
            }

            // Merge the configuration from the command line into the
            // loaded file
            m_Config.Merge(argvConfig);

            // Refresh the startupConfig post merge
            startupConfig = argvConfig.Configs["Startup"];

            // Allow derived classes to load config before the console is
            // opened.
            ReadConfig();

            // Create main console
            string consoleType = "local";

            if (startupConfig != null)
            {
                consoleType = startupConfig.GetString("console", consoleType);
            }

            if (consoleType == "basic")
            {
                MainConsole.Instance = new CommandConsole(prompt);
            }
            else
            {
                MainConsole.Instance = new LocalConsole(prompt);
            }

            // Configure the appenders for log4net
            OpenSimAppender consoleAppender = null;
            FileAppender    fileAppender    = null;

            XmlConfigurator.Configure();

            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[] appenders = repository.GetAppenders();

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    consoleAppender = (OpenSimAppender)appender;
                }

                if (appender.Name == "LogFileAppender")
                {
                    fileAppender = (FileAppender)appender;
                }
            }

            if (consoleAppender == null)
            {
                System.Console.WriteLine("No console appender found. Server can't start");
                Thread.CurrentThread.Abort();
            }
            else
            {
                consoleAppender.Console = MainConsole.Instance;

                if (null == consoleAppender.Threshold)
                {
                    consoleAppender.Threshold = Level.All;
                }
            }

            // Set log file
            if (fileAppender != null)
            {
                if (startupConfig != null)
                {
                    fileAppender.File = startupConfig.GetString("logfile", assemblyName.Name + ".log");
                }
            }

            // Register the quit command
            MainConsole.Instance.Commands.AddCommand("base", false, "quit",
                                                     "quit",
                                                     "Quit the application", HandleQuit);

            // Allow derived classes to perform initialization that
            // needs to be done after the console has opened
            Initialise();
        }