/// <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();
            }
        }
Пример #2
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);
            }
        }