Esempio n. 1
0
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (Force || ShouldContinue(
                    "Are you sure you want to reset this RabbitMq node? Removes the node from any cluster it belongs to, removes all data from the management database, such as configured users and vhosts, and deletes all persistent messages.",
                    "Confirm"))
            {
                WriteVerbose("Reset request confirmed");
            }
            else
            {
                WriteVerbose("Reset aborted");
                return;
            }

            WriteVerbose($"Resetting {Environment.MachineName}");

            var client = new RabbitMqBatCtlClient();

            WriteVerbose("Stopping RabbitMq application");
            client.SoftStop();

            try
            {
                WriteVerbose($"Resetting");
                client.Reset();
            }
            finally
            {
                WriteVerbose("Starting RabbitMq application");
                client.SoftStart();
            }
        }
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqBatCtlClient();

            WriteVerbose("Starting RabbitMq");

            client.SoftStart();
        }
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            var cookieContent = CookieContent.Trim();

            if (string.IsNullOrWhiteSpace(cookieContent))
            {
                throw new Exception("No valid cookie content specified");
            }

            var client = new RabbitMqBatCtlClient();

            WriteVerbose("Stopping RabbitMq node");
            client.HardStop();

            try
            {
                try
                {
                    WriteVerbose($"Setting system cookie contents {InstallationConstants.Erlang.CookieSystemPath}");

                    //remove readonly
                    File.SetAttributes(InstallationConstants.Erlang.CookieSystemPath,
                                       File.GetAttributes(InstallationConstants.Erlang.CookieSystemPath) & ~FileAttributes.ReadOnly);

                    File.WriteAllText(InstallationConstants.Erlang.CookieSystemPath, cookieContent);

                    //add readonly
                    File.SetAttributes(InstallationConstants.Erlang.CookieSystemPath,
                                       File.GetAttributes(InstallationConstants.Erlang.CookieSystemPath) & FileAttributes.ReadOnly);
                }
                catch (Exception ex2)
                {
                    throw new Exception("Failed to set system cookie content.", ex2);
                }

                try
                {
                    WriteVerbose(
                        $"Setting user profile cookie contents {InstallationConstants.Erlang.CookieUserProfilePath}");

                    //remove readonly
                    File.SetAttributes(InstallationConstants.Erlang.CookieUserProfilePath,
                                       File.GetAttributes(InstallationConstants.Erlang.CookieUserProfilePath) &
                                       ~FileAttributes.ReadOnly);

                    File.WriteAllText(InstallationConstants.Erlang.CookieUserProfilePath, cookieContent);

                    //add readonly
                    File.SetAttributes(InstallationConstants.Erlang.CookieUserProfilePath,
                                       File.GetAttributes(InstallationConstants.Erlang.CookieUserProfilePath) &
                                       FileAttributes.ReadOnly);
                }
                catch (Exception ex2)
                {
                    throw new Exception("Failed to set user profile cookie content.", ex2);
                }

                WriteVerbose("Cookie set");

                WriteVerbose("Starting RabbitMq");
                client.SoftStart();
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to set cookie content for clustering. Manual copy and paste is most likely required", ex);
            }
        }
Esempio n. 4
0
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            int[] allPorts  = { 4369, 25672, 44002 };
            int[] livePorts = { 44002 };

            if (FirewallConfigured || ShouldContinue(
                    $"Do you have private/domain firewall ports {string.Join(", ", allPorts)} open on this and the other RabbitMq node?",
                    "Firewall"))
            {
                WriteVerbose("Firewall/network access marked as configured");
            }
            else
            {
                throw new ApplicationException("Network access not configured");
            }

            using (var tcpClient = new TcpClient())
            {
                livePorts.ToList().ForEach(p =>
                {
                    try
                    {
                        WriteVerbose($"Validating connection to {StrictHostname} on port {p}");

                        tcpClient.Connect(StrictHostname, p);

                        tcpClient.Close();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception($"Failed to connect to {StrictHostname} on port {p}", ex);
                    }
                });
            }

            if (CookieSet || ShouldContinue(
                    "Have you set the Erlang cookie to match the one on the node your are joining? See Set-ErlangCookieFileCommand for details",
                    "Cluster cookie"))
            {
                WriteVerbose("Erlang cookie set the same between this and target node");
            }
            else
            {
                throw new ApplicationException("Erlang cookie not set for cluster");
            }

            WriteVerbose($"Clustering {Environment.MachineName} to {StrictHostname}");

            var client = new RabbitMqBatCtlClient();

            WriteVerbose("Stopping RabbitMq application");
            client.SoftStop();

            try
            {
                WriteVerbose($"Joining {StrictHostname}");
                client.JoinCluster(StrictHostname);
            }
            finally
            {
                WriteVerbose("Starting RabbitMq application");
                client.SoftStart();
            }
        }