Exemplo n.º 1
0
        public void Init()
        {
            // Configure Log4Net
            XmlConfigurator.Configure(new FileInfo(Constants.LOG_CONFIG_PATH));

            // Set CWD so that native libs are found.
            Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);

            // Load INI stuff
            var configSource = new ArgvConfigSource(new string[] { });

            // Configure nIni aliases and locale
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", true);

            configSource.Alias.AddAlias("On", true);
            configSource.Alias.AddAlias("Off", false);
            configSource.Alias.AddAlias("True", true);
            configSource.Alias.AddAlias("False", false);
            configSource.Alias.AddAlias("Yes", true);
            configSource.Alias.AddAlias("No", false);

            // Read in the ini file
            configSource.Merge(new IniConfigSource(Constants.INI_PATH));

            // Prep cache folder
            try {
                Directory.Delete(Constants.TEST_CACHE_PATH, true);
            }
            catch (DirectoryNotFoundException) {
                // Skip.
            }

            Directory.CreateDirectory(Constants.TEST_CACHE_PATH);

            // Start booting server
            var pidFileManager = new PIDFileManager(Constants.PID_FILE_PATH);

            var chattelConfigRead = new ChattelConfiguration(Constants.TEST_CACHE_PATH);

            LocalStorage = new AssetStorageSimpleFolderTree(chattelConfigRead);
            var chattelReader = new ChattelReader(chattelConfigRead, LocalStorage);

            _service = new F_Stop(
                Constants.SERVICE_URI,
                Constants.SERVICE_ADMIN_TOKEN,
                TimeSpan.FromSeconds(Constants.SERVICE_NC_LIFETIME_SECONDS),
                chattelReader,
                new List <sbyte> {
                0, 12, /*18, 19,*/ 49
            }
                );

            _service.Start();
        }
Exemplo n.º 2
0
        public static void TestPIDFileManager_Ctor1_Path_PIdFileHasCorrectContents()
        {
            var pidMan = new PIDFileManager(PID_FILE_PATH);

            var expectedContents = GeneratePIdContents(PIDFileManager.Status.Init);

            using (var pidFile = File.OpenRead(PID_FILE_PATH)) {
                var contents = new byte[pidFile.Length];
                pidFile.Read(contents, 0, (int)pidFile.Length);

                Assert.AreEqual(expectedContents, contents);
            }
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            // Please note that if you are changing something in this function you should check to see if you need to change the other server's Main functions as well.

            // Under any circumstance other than an explicit exit the exit code should be 1.
            Environment.ExitCode = 1;

            ServicePointManager.DefaultConnectionLimit = 12;

            // Add the arguments supplied when running the application to the configuration
            var configSource = new ArgvConfigSource(args);

            configSource.Alias.AddAlias("On", true);
            configSource.Alias.AddAlias("Off", false);
            configSource.Alias.AddAlias("True", true);
            configSource.Alias.AddAlias("False", false);
            configSource.Alias.AddAlias("Yes", true);
            configSource.Alias.AddAlias("No", false);

            configSource.AddSwitch("Startup", "background");
            configSource.AddSwitch("Startup", "pidfile");

            m_log.Info("[SERVER]: Launching GridServer...");

            var pidFile = new PIDFileManager(configSource.Configs["Startup"].GetString("pidfile", string.Empty));

            XmlConfigurator.Configure();

            bool background = configSource.Configs["Startup"].GetBoolean("background", false);

            GridServerBase app;

            if (background)
            {
                m_log.Info("[GridServer MAIN]: set to background");
                app = new GridServerBackground();
            }
            else
            {
                m_log.Info("[GridServer MAIN]: set to foreground");
                app = new GridServerBase();
            }

            pidFile.SetStatus(PIDFileManager.Status.Starting);
            app.Startup();

            pidFile.SetStatus(PIDFileManager.Status.Running);
            app.Work();
        }
Exemplo n.º 4
0
        public static void TestPIDFileManager_SetStatus_PIdFileHasCorrectContents()
        {
            var pidMan = new PIDFileManager();

            var expectedContents = GeneratePIdContents(PIDFileManager.Status.Running);

            pidMan.SetStatus(PIDFileManager.Status.Running);

            using (var pidFile = File.OpenRead(PID_FILE_PATH_AUTO)) {
                var contents = new byte[pidFile.Length];
                pidFile.Read(contents, 0, (int)pidFile.Length);

                Assert.AreEqual(expectedContents, contents);
            }
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            ServicePointManager.DefaultConnectionLimit = 12;

            PIDFileManager pidFile = new PIDFileManager();

            XmlConfigurator.Configure();

            m_log.Info("Launching UserServer...");

            OpenUser_Main userserver = new OpenUser_Main();

            pidFile.SetStatus(PIDFileManager.Status.Starting);
            userserver.Startup();

            pidFile.SetStatus(PIDFileManager.Status.Running);
            userserver.Work();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:LibWhipLru.WhipLru"/> class.
        /// </summary>
        /// <param name="address">Address to listen on.</param>
        /// <param name="port">Port to listen on.</param>
        /// <param name="password">Password to filter conenctions by.</param>
        /// <param name="pidFileManager">Pidfile manager.</param>
        /// <param name="storageManager">Storage manager.</param>
        /// <param name="listenBacklogLength">Listen backlog length.</param>
        public WhipLru(
            string address,
            uint port,
            string password,
            PIDFileManager pidFileManager,
            StorageManager storageManager,
            uint listenBacklogLength = WHIPServer.DEFAULT_BACKLOG_LENGTH
            )
        {
            LOG.Debug($"{address}:{port} - Initializing service.");

            if (port > 0xFFFF)               // Only 16 bits worth of ports out there.
            {
                throw new ArgumentOutOfRangeException(nameof(port), "Port must be between 0 and 65535 inclusive!");
            }

            if (listenBacklogLength <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(listenBacklogLength), "Having a backlog of nothing makes no sense!");
            }

            _address = address ?? throw new ArgumentNullException(nameof(address));

            // Verify the address is either in IPv4 dotted notation, or IPv6 colon notation, AND that it's a valid IP address.
            if (!((address.Contains(".") || address.Contains(":")) && System.Net.IPAddress.TryParse(address, out var addr)))
            {
                throw new ArgumentOutOfRangeException(nameof(address), "A valid IPv4 or IPv6 address is needed.");
            }

            _port                = port;
            _password            = password;
            _listenBacklogLength = listenBacklogLength;

            _storageManager = storageManager ?? throw new ArgumentNullException(nameof(storageManager));
            _pidFileManager = pidFileManager ?? throw new ArgumentNullException(nameof(pidFileManager));

            _pidFileManager?.SetStatus(PIDFileManager.Status.Ready);
        }
Exemplo n.º 7
0
        public static int Main(string[] args)
        {
            // First line, hook the appdomain to the crash reporter
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "70a9f94f-59e8-4073-93ab-00aaacc26111", out var createdNew);

            if (!createdNew)
            {
                LOG.Error("Server process already started, please stop that server first.");
                return(2);
            }

            // Add the arguments supplied when running the application to the configuration
            var configSource = new ArgvConfigSource(args);

            // Commandline switches
            configSource.AddSwitch("Startup", "inifile");
            configSource.AddSwitch("Startup", "logconfig");
            configSource.AddSwitch("Startup", "pidfile");
            configSource.AddSwitch("Startup", "purge");

            var startupConfig = configSource.Configs["Startup"];

            var pidFileManager = new PIDFileManager(startupConfig.GetString("pidfile", string.Empty));

            // Configure Log4Net
            {
                var logConfigFile = startupConfig.GetString("logconfig", string.Empty);
                if (string.IsNullOrEmpty(logConfigFile))
                {
                    XmlConfigurator.Configure();
                    LogBootMessage();
                    LOG.Info("Configured log4net using ./WHIP_LRU.exe.config as the default.");
                }
                else
                {
                    XmlConfigurator.Configure(new FileInfo(logConfigFile));
                    LogBootMessage();
                    LOG.Info($"Configured log4net using \"{logConfigFile}\" as configuration file.");
                }
            }

            // Configure nIni aliases and locale
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", true);

            configSource.Alias.AddAlias("On", true);
            configSource.Alias.AddAlias("Off", false);
            configSource.Alias.AddAlias("True", true);
            configSource.Alias.AddAlias("False", false);
            configSource.Alias.AddAlias("Yes", true);
            configSource.Alias.AddAlias("No", false);

            var     isRunning = true;
            WhipLru whipLru   = null;

            // Handlers for signals.
            UnixSignal[] signals = null;
            if (ON_POSIX_COMPLAINT_OS)
            {
                signals = new [] {
                    new UnixSignal(Signum.SIGINT),
                    new UnixSignal(Signum.SIGTERM),
                    new UnixSignal(Signum.SIGHUP),
                };
            }
            else
            {
                Console.CancelKeyPress += (sender, cargs) => {
                    LOG.Debug("CTRL-C pressed, terminating.");
                    isRunning = false;
                    whipLru?.Stop();

                    cargs.Cancel = true;
                    waitHandle.Set();
                };
            }

            while (isRunning)
            {
                // Dump any known servers, we're going to reconfigure them.
                foreach (var server in _assetServersByName.Values)
                {
                    server.Dispose();
                }
                // TODO: might need to double buffer these, or something, so that old ones can finish out before being disposed.

                // Read in the ini file
                ReadConfigurationFromINI(configSource);

                // Read in a config list that lists the priority order of servers and their settings.

                var configRead  = configSource.Configs["AssetsRead"];
                var configWrite = configSource.Configs["AssetsWrite"];

                var serversRead  = GetServers(configSource, configRead, _assetServersByName);
                var serversWrite = GetServers(configSource, configWrite, _assetServersByName);

                var localStorageConfig = configSource.Configs["LocalStorage"];

                var chattelConfigRead  = GetConfig(localStorageConfig, serversRead);
                var chattelConfigWrite = GetConfig(localStorageConfig, serversWrite);

                var serverConfig = configSource.Configs["Server"];

                var address  = serverConfig?.GetString("Address", WHIPServer.DEFAULT_ADDRESS) ?? WHIPServer.DEFAULT_ADDRESS;
                var port     = (uint?)serverConfig?.GetInt("Port", (int)WHIPServer.DEFAULT_PORT) ?? WHIPServer.DEFAULT_PORT;
                var password = serverConfig?.GetString("Password", WHIPServer.DEFAULT_PASSWORD);
                if (password == null)                   // Would only be null if serverConfig was null or DEFAULT_PASSWORD is null.  Why not use the ?? operator? Compiler didn't like it.
                {
                    password = WHIPServer.DEFAULT_PASSWORD;
                }
                var listenBacklogLength = (uint?)serverConfig?.GetInt("ConnectionQueueLength", (int)WHIPServer.DEFAULT_BACKLOG_LENGTH) ?? WHIPServer.DEFAULT_BACKLOG_LENGTH;

                var maxAssetLocalStorageDiskSpaceByteCount = (ulong?)localStorageConfig?.GetLong("MaxDiskSpace", (long)AssetLocalStorageLmdbPartitionedLRU.DB_MAX_DISK_BYTES_MIN_RECOMMENDED) ?? AssetLocalStorageLmdbPartitionedLRU.DB_MAX_DISK_BYTES_MIN_RECOMMENDED;
                var negativeCacheItemLifetime = TimeSpan.FromSeconds((uint?)localStorageConfig?.GetInt("NegativeCacheItemLifetimeSeconds", (int)StorageManager.DEFAULT_NC_LIFETIME_SECONDS) ?? StorageManager.DEFAULT_NC_LIFETIME_SECONDS);
                var partitionInterval         = TimeSpan.FromMinutes((uint?)localStorageConfig?.GetInt("MinutesBetweenDatabasePartitions", (int)DEFAULT_DB_PARTITION_INTERVAL_MINUTES) ?? DEFAULT_DB_PARTITION_INTERVAL_MINUTES);

                var purgeAll = startupConfig.GetString("purge", string.Empty) == "all";
                if (purgeAll)
                {
                    LOG.Info("CLI request to purge all assets on startup specified.");
                }

                var readerLocalStorage = new AssetLocalStorageLmdbPartitionedLRU(
                    chattelConfigRead,
                    maxAssetLocalStorageDiskSpaceByteCount,
                    partitionInterval
                    );
                var chattelReader = new ChattelReader(chattelConfigRead, readerLocalStorage, purgeAll);
                var chattelWriter = new ChattelWriter(chattelConfigWrite, readerLocalStorage, purgeAll);

                var storageManager = new StorageManager(
                    readerLocalStorage,
                    negativeCacheItemLifetime,
                    chattelReader,
                    chattelWriter
                    );

                whipLru = new WhipLru(
                    address,
                    port,
                    password,
                    pidFileManager,
                    storageManager,
                    listenBacklogLength
                    );

                whipLru.Start();

                if (signals != null)
                {
                    var signalIndex = UnixSignal.WaitAny(signals, -1);

                    switch (signals[signalIndex].Signum)
                    {
                    case Signum.SIGHUP:
                        whipLru.Stop();
                        break;

                    case Signum.SIGINT:
                    case Signum.SIGKILL:
                        isRunning = false;
                        whipLru.Stop();
                        break;

                    default:
                        // Signal unknown, ignore it.
                        break;
                    }
                }
                else
                {
                    waitHandle.WaitOne();
                }
            }

            foreach (var server in _assetServersByName.Values)
            {
                server.Dispose();
            }

            return(0);
        }
Exemplo n.º 8
0
        public static void TestPIDFileManager_Ctor0_CreatesPIdFile()
        {
            var pidMan = new PIDFileManager();

            FileAssert.Exists(PID_FILE_PATH_AUTO);
        }
Exemplo n.º 9
0
        public static void TestPIDFileManager_SetStatus_DoesntThrow()
        {
            var pidMan = new PIDFileManager();

            Assert.DoesNotThrow(() => pidMan.SetStatus(PIDFileManager.Status.Running));
        }
Exemplo n.º 10
0
        public static void TestPIDFileManager_Ctor1_Path_CreatesAutoPIdFile()
        {
            var pidMan = new PIDFileManager(PID_FILE_PATH);

            FileAssert.Exists(PID_FILE_PATH);
        }
Exemplo n.º 11
0
        public static void TestPIDFileManager_Ctor1_Empty_CreatesAutoPIdFile()
        {
            var pidMan = new PIDFileManager(string.Empty);

            FileAssert.Exists(PID_FILE_PATH_AUTO);
        }
Exemplo n.º 12
0
        public static void TestPIDFileManager_Ctor1_Null_CreatesAutoPIdFile()
        {
            var pidMan = new PIDFileManager(null);

            FileAssert.Exists(PID_FILE_PATH_AUTO);
        }
Exemplo n.º 13
0
        //could move our main function into OpenSimMain and kill this class
        public static void Main(string[] args)
        {
            // Under any circumstance other than an explicit exit the exit code should be 1.
            Environment.ExitCode = 1;

            // First line, hook the appdomain to the crash reporter
            AppDomain.CurrentDomain.UnhandledException +=
                new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            ServicePointManager.DefaultConnectionLimit = 12;

            // Add the arguments supplied when running the application to the configuration
            var configSource = new ArgvConfigSource(args);

            configSource.AddSwitch("Startup", "pidfile");
            var pidFile = new PIDFileManager(configSource.Configs["Startup"].GetString("pidfile", string.Empty));

            pidFile.SetStatus(PIDFileManager.Status.Starting);
            // Configure Log4Net
            configSource.AddSwitch("Startup", "logconfig");
            string logConfigFile = configSource.Configs["Startup"].GetString("logconfig", String.Empty);

            if (!String.IsNullOrEmpty(logConfigFile))
            {
                XmlConfigurator.Configure(new System.IO.FileInfo(logConfigFile));
                m_log.InfoFormat("[HALCYON MAIN]: configured log4net using \"{0}\" as configuration file",
                                 logConfigFile);
            }
            else
            {
                XmlConfigurator.Configure();
                m_log.Info("[HALCYON MAIN]: configured log4net using default Halcyon.exe.config");
            }

            m_log.Info("Performing compatibility checks... ");
            string supported = String.Empty;

            if (Util.IsEnvironmentSupported(ref supported))
            {
                m_log.Info("Environment is compatible.\n");
            }
            else
            {
                m_log.Warn("Environment is unsupported (" + supported + ")\n");
            }

            // Configure nIni aliases and localles
            Culture.SetCurrentCulture();

            configSource.Alias.AddAlias("On", true);
            configSource.Alias.AddAlias("Off", false);
            configSource.Alias.AddAlias("True", true);
            configSource.Alias.AddAlias("False", false);
            configSource.Alias.AddAlias("Yes", true);
            configSource.Alias.AddAlias("No", false);

            configSource.AddSwitch("Startup", "background");
            configSource.AddSwitch("Startup", "inifile");
            configSource.AddSwitch("Startup", "inimaster");
            configSource.AddSwitch("Startup", "inidirectory");
            configSource.AddSwitch("Startup", "gridmode");
            configSource.AddSwitch("Startup", "physics");
            configSource.AddSwitch("Startup", "gui");
            configSource.AddSwitch("Startup", "console");
            configSource.AddSwitch("Startup", "save_crashes");
            configSource.AddSwitch("Startup", "crash_dir");

            configSource.AddConfig("StandAlone");
            configSource.AddConfig("Network");

            // Check if we're running in the background or not
            bool background = configSource.Configs["Startup"].GetBoolean("background", false);

            // Check if we're saving crashes
            m_saveCrashDumps = configSource.Configs["Startup"].GetBoolean("save_crashes", false);

            // load Crash directory config
            m_crashDir = configSource.Configs["Startup"].GetString("crash_dir", m_crashDir);

            if (background)
            {
                m_sim = new OpenSimBackground(configSource);
                pidFile.SetStatus(PIDFileManager.Status.Running);
                m_sim.Startup();
            }
            else
            {
                m_sim = new OpenSim(configSource);

                m_sim.Startup();

                pidFile.SetStatus(PIDFileManager.Status.Running);
                while (true)
                {
                    try
                    {
                        // Block thread here for input
                        MainConsole.Instance.Prompt();
                    }
                    catch (Exception e)
                    {
                        m_log.ErrorFormat("Command error: {0}", e);
                    }
                }
            }
        }
Exemplo n.º 14
0
        public static int Main(string[] args)
        {
            // First line, hook the appdomain to the crash reporter
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            var createdNew = true;
            var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "70a9f94f-59e8-4073-93ab-00aaacc26111", out createdNew);

            if (!createdNew)
            {
                LOG.Error("Server process already started, please stop that server first.");
                return(2);
            }

            // Add the arguments supplied when running the application to the configuration
            var configSource = new ArgvConfigSource(args);

            // Commandline switches
            configSource.AddSwitch("Startup", "inifile");
            configSource.AddSwitch("Startup", "logconfig");
            configSource.AddSwitch("Startup", "pidfile");

            var startupConfig = configSource.Configs["Startup"];

            var pidFileManager = new PIDFileManager(startupConfig.GetString("pidfile", string.Empty));

            // Configure Log4Net
            var logConfigFile = startupConfig.GetString("logconfig", string.Empty);

            if (string.IsNullOrEmpty(logConfigFile))
            {
                XmlConfigurator.Configure();
                LogBootMessage();
                LOG.Info("Configured log4net using ./WHIP_LRU.exe.config as the default.");
            }
            else
            {
                XmlConfigurator.Configure(new FileInfo(logConfigFile));
                LogBootMessage();
                LOG.Info($"Configured log4net using \"{logConfigFile}\" as configuration file.");
            }

            // Configure nIni aliases and locale
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", true);

            configSource.Alias.AddAlias("On", true);
            configSource.Alias.AddAlias("Off", false);
            configSource.Alias.AddAlias("True", true);
            configSource.Alias.AddAlias("False", false);
            configSource.Alias.AddAlias("Yes", true);
            configSource.Alias.AddAlias("No", false);

            var isRunning = true;

            F_Stop f_stop = null;

            // Handlers for signals.
            Console.CancelKeyPress += (sender, cargs) => {
                LOG.Debug("CTRL-C pressed, terminating.");
                isRunning = false;
                f_stop?.Stop();

                cargs.Cancel = true;
                waitHandle.Set();
            };

            // TODO: incorporate UNIX signals for reloading etc, once the crossplatform kinks have been worked out in WHIP-LRU.

            while (isRunning)
            {
                // Read in the ini file
                ReadConfigurationFromINI(configSource);

                var configRead = configSource.Configs["AssetsRead"];

                var serversRead = GetServers(configSource, configRead, _assetServersByName);

                var chattelConfigRead = GetConfig(configRead, serversRead);

                var chattelReader = new ChattelReader(chattelConfigRead);

                var serverConfig = configSource.Configs["Server"];

                var address = serverConfig?.GetString("Address", F_Stop.DEFAULT_ADDRESS) ?? F_Stop.DEFAULT_ADDRESS;
                if (address == "*")
                {
                    address = "localhost";
                }
                var port            = (uint?)serverConfig?.GetInt("Port", (int)F_Stop.DEFAULT_PORT) ?? F_Stop.DEFAULT_PORT;
                var useSSL          = serverConfig?.GetBoolean("UseSSL", F_Stop.DEFAULT_USE_SSL) ?? F_Stop.DEFAULT_USE_SSL;
                var adminToken      = serverConfig?.GetString("AdminToken", F_Stop.DEFAULT_ADMIN_TOKEN) ?? F_Stop.DEFAULT_ADMIN_TOKEN;
                var validAssetTypes = serverConfig?.GetString("AllowedAssetTypes", F_Stop.DEFAULT_VALID_ASSET_TYPES) ?? F_Stop.DEFAULT_VALID_ASSET_TYPES;

                var cacheConfig = configSource.Configs["Cache"];

                var negativeCacheItemLifetime = TimeSpan.FromSeconds((uint?)cacheConfig?.GetInt("NegativeCacheItemLifetimeSeconds", (int)F_Stop.DEFAULT_NC_LIFETIME_SECONDS) ?? F_Stop.DEFAULT_NC_LIFETIME_SECONDS);

                var protocol = useSSL ? "https" : "http";

                var uri = new Uri($"{protocol}://{address}:{port}");
                f_stop = new F_Stop(
                    uri,
                    adminToken,
                    negativeCacheItemLifetime,
                    chattelReader,
                    validAssetTypes.Split(',').Select(type => sbyte.Parse(type))
                    );

                f_stop.Start();

                waitHandle.WaitOne();
            }

            return(0);
        }