Пример #1
0
        private static void Shutdown()
        {
            logger.Info(() => "Shutdown ...");
            Console.WriteLine("Shutdown...");

            shareRelay?.Stop();
            shareRecorder?.Stop();
            statsRecorder?.Stop();
        }
Пример #2
0
        private static void Shutdown()
        {
            logger.Info(() => "Shutdown ...");

            shareRelay.Stop();
            shareRecorder.Stop();
            statsRecorder.Stop();

            Process.GetCurrentProcess().Close();
        }
Пример #3
0
        private static void Shutdown()
        {
            logger.Info(() => "Shutdown ...");
            Console.WriteLine("Shutdown...");

            foreach (var pool in pools.Values)
            {
                pool.Stop();
            }

            shareRelay?.Stop();
            shareRecorder?.Stop();
            statsRecorder?.Stop();
        }
Пример #4
0
        internal static void StartMiningCorePool(string configFile)
        {
            try
            {
                // Display Software Version Info
                var basePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                Console.WriteLine($"{Assembly.GetEntryAssembly().GetName().Name} - MinerNL build v{Assembly.GetEntryAssembly().GetName().Version}");
                Console.WriteLine($"Run location: {basePath}");
                Console.WriteLine(" ");

                // log unhandled program exception errors
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MC_UnhandledException);
                currentDomain.ProcessExit        += OnProcessExit;
                Console.CancelKeyPress           += new ConsoleCancelEventHandler(OnCancelKeyPress);

                // ValidateRuntimeEnvironment();
                // root check
                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.UserName == "root")
                {
                    logger.Warn(() => "Running as root is discouraged!");
                }

                // require 64-bit Windows OS
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.ProcessArchitecture == Architecture.X86)
                {
                    throw new PoolStartupAbortException("Miningcore requires 64-Bit Windows");
                }

                // Read config.json file
                clusterConfig = PoolConfig.GetConfigContent(configFile);

                // Initialize Logging
                FileLogger.ConfigureLogging();

                // LogRuntimeInfo();
                //-----------------------------------------------------------------------------
                logger.Info(() => $"{RuntimeInformation.FrameworkDescription.Trim()} on {RuntimeInformation.OSDescription.Trim()} [{RuntimeInformation.ProcessArchitecture}]");

                // Bootstrap();
                //-----------------------------------------------------------------------------
                ZcashNetworks.Instance.EnsureRegistered();

                // Service collection
                var builder = new ContainerBuilder();
                builder.RegisterAssemblyModules(typeof(AutofacModule).GetTypeInfo().Assembly);
                builder.RegisterInstance(clusterConfig);
                builder.RegisterInstance(pools);
                builder.RegisterInstance(gcStats);

                // AutoMapper
                var amConf = new MapperConfiguration(cfg => { cfg.AddProfile(new AutoMapperProfile()); });
                builder.Register((ctx, parms) => amConf.CreateMapper());

                PostgresInterface.ConnectDatabase(builder);
                container = builder.Build();

                // Configure Equihash
                if (clusterConfig.EquihashMaxThreads.HasValue)
                {
                    EquihashSolver.MaxThreads = clusterConfig.EquihashMaxThreads.Value;
                }

                MonitorGarbageCollection();

                // Start Miningcore Pool Services
                if (!cts.IsCancellationRequested)
                {
                    StartMiningcorePoolServices().Wait(cts.Token);
                }
            }

            catch (PoolStartupAbortException ex)
            {
                if (!string.IsNullOrEmpty(ex.Message))
                {
                    Console.WriteLine(ex.Message);
                }

                Console.WriteLine("\nCluster cannot start. Good Bye!");
            }

            catch (JsonException)
            {
                // ignored
            }

            catch (IOException)
            {
                // ignored
            }

            catch (AggregateException ex)
            {
                if (!(ex.InnerExceptions.First() is PoolStartupAbortException))
                {
                    Console.WriteLine(ex);
                }

                Console.WriteLine("Cluster cannot start. Good Bye!");
            }

            catch (OperationCanceledException)
            {
                // Ctrl+C
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex);

                Console.WriteLine("Cluster cannot start. Good Bye!");
            }

            finally
            {
                // Shutdown();
                Console.WriteLine("Miningcore is shuting down... bye!");
                logger?.Info(() => "Miningcore is shuting down... bye!");

                foreach (var poolToStop in pools.Values)
                {
                    Console.WriteLine($"Stopping pool {poolToStop}");
                    poolToStop.Stop();
                }

                shareRelay?.Stop();
                shareReceiver?.Stop();
                shareRecorder?.Stop();
                statsRecorder?.Stop();
                Process.GetCurrentProcess().Kill();
            }
        }