Exemplo n.º 1
0
        public bool Upgrade(ServiceControlInstance instance, InstanceUpgradeOptions options)
        {
            ZipInfo.ValidateZip();

            var checkLicenseResult = CheckLicenseIsValid();

            if (!checkLicenseResult.Valid)
            {
                logger.Error($"Upgrade aborted - {checkLicenseResult.Message}");
                return(false);
            }

            instance.ReportCard = new ReportCard();

            var restartService = instance.Service.Status == ServiceControllerStatus.Running;

            if (!instance.TryStopService())
            {
                logger.Error("Service failed to stop or service stop timed out");
            }
            try
            {
                var backupFile = instance.BackupAppConfig();
                try
                {
                    instance.UpgradeFiles(ZipInfo.FilePath);
                }
                finally
                {
                    instance.RestoreAppConfig(backupFile);
                }

                options.ApplyChangesToInstance(instance);
                instance.SetupInstance();

                if (instance.ReportCard.HasErrors)
                {
                    foreach (var error in instance.ReportCard.Errors)
                    {
                        logger.Error(error);
                    }
                    return(false);
                }

                if (restartService && !instance.TryStartService())
                {
                    logger.Error("Service failed to start after update - please check configuration for {0}", instance.Name);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Upgrade Failed: {0}", ex.Message);
                return(false);
            }



            return(true);
        }
Exemplo n.º 2
0
        internal ReportCard Upgrade(ServiceControlInstance instance, ServiceControlUpgradeOptions upgradeOptions, IProgress <ProgressDetails> progress = null)
        {
            progress = progress ?? new Progress <ProgressDetails>();

            instance.ReportCard = new ReportCard();
            ZipInfo.ValidateZip();

            var totalSteps  = 7 - (upgradeOptions.UpgradeInfo.DeleteIndexes ? 0 : 1) - (upgradeOptions.UpgradeInfo.DataBaseUpdate ? 0 : 1);
            var currentStep = 0;

            progress.Report(currentStep++, totalSteps, "Stopping instance...");
            if (!instance.TryStopService())
            {
                return(new ReportCard
                {
                    Errors = { "Service failed to stop" },
                    Status = Status.Failed
                });
            }

            progress.Report(currentStep++, totalSteps, "Backing up app.config...");
            var backupFile = instance.BackupAppConfig();

            try
            {
                progress.Report(currentStep++, totalSteps, "Upgrading Files...");
                instance.UpgradeFiles(ZipInfo.FilePath);
            }
            finally
            {
                progress.Report(currentStep++, totalSteps, "Restoring app.config...");
                instance.RestoreAppConfig(backupFile);
            }

            upgradeOptions.ApplyChangesToInstance(instance);

            if (upgradeOptions.UpgradeInfo.DeleteIndexes)
            {
                progress.Report(currentStep++, totalSteps, "Removing database indexes...");
                instance.RemoveDatabaseIndexes();
            }

            if (upgradeOptions.UpgradeInfo.DataBaseUpdate)
            {
                progress.Report(currentStep, totalSteps, "Updating Database...");
                // ReSharper disable once AccessToModifiedClosure
                instance.UpdateDatabase(msg => progress.Report(currentStep, totalSteps, $"Updating Database...{Environment.NewLine}{msg}"));
            }

            progress.Report(++currentStep, totalSteps, "Running Queue Creation...");
            instance.SetupInstance();

            instance.ReportCard.SetStatus();
            return(instance.ReportCard);
        }
        public bool Upgrade(ServiceControlInstance instance, ServiceControlUpgradeOptions options)
        {
            if (instance.Version < options.UpgradeInfo.CurrentMinimumVersion)
            {
                logger.Error($"Upgrade aborted. An interim upgrade to version {options.UpgradeInfo.RecommendedUpgradeVersion} is required before upgrading to version {ZipInfo.Version}. Download available at https://github.com/Particular/ServiceControl/releases/tag/{options.UpgradeInfo.RecommendedUpgradeVersion}");
                return(false);
            }

            ZipInfo.ValidateZip();

            var checkLicenseResult = CheckLicenseIsValid();

            if (!checkLicenseResult.Valid)
            {
                logger.Error($"Upgrade aborted - {checkLicenseResult.Message}");
                return(false);
            }

            instance.ReportCard = new ReportCard();

            var restartService = instance.Service.Status == ServiceControllerStatus.Running;

            if (!instance.TryStopService())
            {
                logger.Error("Service failed to stop or service stop timed out");
            }

            try
            {
                var backupFile = instance.BackupAppConfig();
                try
                {
                    instance.UpgradeFiles(ZipInfo.FilePath);
                }
                finally
                {
                    instance.RestoreAppConfig(backupFile);
                }

                options.ApplyChangesToInstance(instance);

                if (options.UpgradeInfo.DeleteIndexes)
                {
                    instance.RemoveDatabaseIndexes();
                }

                if (options.UpgradeInfo.DataBaseUpdate)
                {
                    instance.UpdateDatabase(msg => { });
                }

                instance.SetupInstance();

                if (instance.ReportCard.HasErrors)
                {
                    foreach (var error in instance.ReportCard.Errors)
                    {
                        logger.Error(error);
                    }

                    return(false);
                }

                if (restartService && !instance.TryStartService())
                {
                    logger.Error("Service failed to start after update - please check configuration for {0}", instance.Name);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Upgrade Failed: {0}", ex.Message);
                return(false);
            }

            return(true);
        }