Add unattended upgrade support

This commit is contained in:
Rasmus John Pedersen
2020-12-08 09:06:28 +01:00
parent e8b8723f51
commit 5efc1817d6
3 changed files with 34 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Logging.Serilog;
using Umbraco.Core.Migrations.Install;
using Umbraco.Core.Migrations.Upgrade;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Sync;
@@ -189,6 +190,16 @@ namespace Umbraco.Core.Runtime
// create the factory
_factory = Current.Factory = composition.CreateFactory();
// if level is Run and reason is UpgradeMigrations, that means we need to perform an unattended upgrade
if (_state.Reason == RuntimeLevelReason.UpgradeMigrations && _state.Level == RuntimeLevel.Run)
{
// do the upgrade
DoUnattendedUpgrade(_factory.GetInstance<DatabaseBuilder>());
// upgrade is done, set reason to Run
_state.Reason = RuntimeLevelReason.Run;
}
// create & initialize the components
_components = _factory.GetInstance<ComponentCollection>();
_components.Initialize();
@@ -288,6 +299,17 @@ namespace Umbraco.Core.Runtime
}
}
private void DoUnattendedUpgrade(DatabaseBuilder databaseBuilder)
{
var plan = new UmbracoPlan();
Logger.Info<CoreRuntime>("Starting unattended upgrade.");
var result = databaseBuilder.UpgradeSchemaAndData(plan);
Logger.Info<CoreRuntime>("Unattended upgrade completed.");
if (result.Success == false)
throw new UnattendedInstallException("An error occurred while running the unattended upgrade.\n" + result.Message);
}
protected virtual void ConfigureUnhandledException()
{
//take care of unhandled exceptions - there is nothing we can do to

View File

@@ -23,6 +23,7 @@ namespace Umbraco.Core
private static bool? _installMissingDatabase;
private static bool? _installEmptyDatabase;
private static bool? _installUnattended;
private static bool? _upgradeUnattended;
// reads a boolean appSetting
private static bool BoolSetting(string key, bool missing) => ConfigurationManager.AppSettings[key]?.InvariantEquals("true") ?? missing;
@@ -66,6 +67,15 @@ namespace Umbraco.Core
set => _installUnattended = value;
}
/// <summary>
/// Gets a value indicating whether unattended upgrade is enabled.
/// </summary>
public static bool UpgradeUnattended
{
get => _upgradeUnattended ?? BoolSetting("Umbraco.Core.RuntimeState.UpgradeUnattended", false);
set => _upgradeUnattended = value;
}
/// <summary>
/// Executes the RuntimeBoot handlers.
/// </summary>

View File

@@ -130,7 +130,7 @@ namespace Umbraco.Core
{
var localVersion = UmbracoVersion.LocalVersion; // the local, files, version
var codeVersion = SemanticVersion; // the executing code version
if (localVersion == null)
{
// there is no local version, we are not installed
@@ -202,7 +202,7 @@ namespace Umbraco.Core
// although the files version matches the code version, the database version does not
// which means the local files have been upgraded but not the database - need to upgrade
_logger.Debug<RuntimeState>("Has not reached the final upgrade step, need to upgrade Umbraco.");
Level = RuntimeLevel.Upgrade;
Level = RuntimeOptions.UpgradeUnattended ? RuntimeLevel.Run : RuntimeLevel.Upgrade;
Reason = RuntimeLevelReason.UpgradeMigrations;
}
break;