Exemplo 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();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Processes the record.
        /// </summary>
        /// <exception cref="System.Exception">
        ///     Failed to create user. Manual creation might be necessary
        ///     or
        ///     Failed to grant permissions to user. Manual grant might be necessary
        /// </exception>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqBatCtlClient();

            WriteVerbose($"Granting permissions to user {UserName}");

            client.GrantPermissionsToUser(VirtualHost, UserName);
        }
        /// <summary>
        ///     Processes the record.
        /// </summary>
        /// <exception cref="System.Exception">
        ///     Failed to create user. Manual creation might be necessary
        ///     or
        ///     Failed to grant permissions to user. Manual grant might be necessary
        /// </exception>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqBatCtlClient();

            WriteVerbose($"Adding limited-access user {Credential.UserName}");

            client.CreateLimitedAccessUser(Credential.UserName, Credential.GetNetworkCredential().Password);
        }
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqBatCtlClient();

            WriteVerbose("Starting RabbitMq");

            client.SoftStart();
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            WriteVerbose($"Removing {StrictHostname} from cluster");

            var client = new RabbitMqBatCtlClient();

            WriteVerbose($"Removing {StrictHostname}");
            client.RemoveFromClusterCluster(StrictHostname);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqBatCtlClient();

            WriteVerbose("Reading RabbitMq status");

            if (!client.IsRunning)
            {
                throw new Exception("RabbitMq is not running");
            }

            WriteVerbose("RabbitMq is running");
        }
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqBatCtlClient();

            WriteVerbose("Stopping RabbitMq");

            if (StopErlangNode)
            {
                WriteVerbose("Stopping RabbitMq and Erlang node");
                client.HardStop();
            }
            else
            {
                WriteVerbose("Stopping RabbitMq but leaving Erlang node running");
                client.SoftStop();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqBatCtlClient();

            if (client.Exists)
            {
                try
                {
                    WriteVerbose("Stopping RabbitMq");

                    client.HardStop();
                }
                catch (Exception ex)
                {
                    throw new Exception("Failed to stop RabbitMq. Manual stop/uninstall might be necessary", ex);
                }
            }

            WriteVerbose("Un-installing prior versions of RabbitMq");

            var executablePaths = InstallationConstants.RabbitMq.UninstallerPaths;

            var externalProcessRunner = new ExternalProcessRunner();

            var shouldDeleteService = false;

            foreach (var executablePath in executablePaths)
            {
                var directoryInfo = new FileInfo(executablePath);
                var workingPath   = directoryInfo.DirectoryName;

                if (!File.Exists(executablePath))
                {
                    //WriteVerbose("No uninstaller found at " + executablePath);

                    CleanUpFolders(workingPath);

                    continue;
                }

                shouldDeleteService = true;

                const string silent = "/S";

                externalProcessRunner.Run(executablePath, workingPath, silent);

                WriteVerbose("Waiting for RabbitMq process to exit...");

                var binPath = Path.Combine(workingPath, InstallationConstants.RabbitMq.BinDir);

                if (Directory.Exists(binPath))
                {
                    //rabbit mq uninstaller seems to be async so we need to monitor the install directory until it's empty
                    while (Directory.Exists(binPath) &&
                           Directory.EnumerateFiles(binPath).Any())
                    {
                        Task.Delay(TimeSpan.FromSeconds(1)).Wait();
                    }

                    //one last wait for system to release resources
                    Task.Delay(TimeSpan.FromSeconds(1)).Wait();
                }

                CleanUpFolders(workingPath);
            }

            if (shouldDeleteService)
            {
                WriteVerbose("Removing RabbitMq windows service");

                try
                {
                    const string serviceToDelete = " delete RabbitMQ";
                    externalProcessRunner.Run("sc", Directory.GetCurrentDirectory(), serviceToDelete);
                }
                catch (Exception ex)
                {
                    WriteWarning("Failed to remove RabbitMq windows service. Clean removal might fail: " + ex.Message);
                }
            }


            WriteVerbose("Uninstallation process completed");
        }
        /// <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);
            }
        }
Exemplo n.º 10
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();
            }
        }