From 9a49ab712b0f244c3e6522ecf654c072eaacba7b Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Wed, 24 Jul 2024 18:36:17 +0200 Subject: [PATCH] Add Health Check for Runtime mode (#16715) * Add Health Check for Runtime mode * Update src/Umbraco.Core/EmbeddedResources/Lang/en.xml Co-authored-by: Jason Elkin * Update src/Umbraco.Core/HealthChecks/Checks/LiveEnvironment/RuntimeModeCheck.cs Co-authored-by: Jason Elkin * Update lang file * Fix typo. --------- Co-authored-by: Jason Elkin --- src/Umbraco.Core/Constants-HealthChecks.cs | 1 + .../EmbeddedResources/Lang/en.xml | 4 +- .../EmbeddedResources/Lang/en_us.xml | 2 + .../LiveEnvironment/RuntimeModeCheck.cs | 53 +++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/Umbraco.Core/HealthChecks/Checks/LiveEnvironment/RuntimeModeCheck.cs diff --git a/src/Umbraco.Core/Constants-HealthChecks.cs b/src/Umbraco.Core/Constants-HealthChecks.cs index 256efbcc5478..bb18145401e9 100644 --- a/src/Umbraco.Core/Constants-HealthChecks.cs +++ b/src/Umbraco.Core/Constants-HealthChecks.cs @@ -22,6 +22,7 @@ public static class DocumentationLinks public static class LiveEnvironment { public const string CompilationDebugCheck = "https://umbra.co/healthchecks-compilation-debug"; + public const string RuntimeModeCheck = "https://docs.umbraco.com/umbraco-cms/fundamentals/setup/server-setup/runtime-modes"; } public static class Configuration diff --git a/src/Umbraco.Core/EmbeddedResources/Lang/en.xml b/src/Umbraco.Core/EmbeddedResources/Lang/en.xml index 599232b13ae1..893ab7c242d6 100644 --- a/src/Umbraco.Core/EmbeddedResources/Lang/en.xml +++ b/src/Umbraco.Core/EmbeddedResources/Lang/en.xml @@ -1,4 +1,4 @@ - + The Umbraco community @@ -428,6 +428,8 @@ Debug compilation mode is currently enabled. It is recommended to disable this setting before go live. + Runtime mode is set to production. + Runtime mode is not set to Production. It is recommended to set the Runtime Mode to Production for live/production environments. diff --git a/src/Umbraco.Core/EmbeddedResources/Lang/en_us.xml b/src/Umbraco.Core/EmbeddedResources/Lang/en_us.xml index 7517a43b12f1..69558f72dace 100644 --- a/src/Umbraco.Core/EmbeddedResources/Lang/en_us.xml +++ b/src/Umbraco.Core/EmbeddedResources/Lang/en_us.xml @@ -419,6 +419,8 @@ Debug compilation mode is currently enabled. It is recommended to disable this setting before go live. + Runtime mode is set to production. + Runtime mode is not set to Production. It is recommended to set the Runtime Mode to Production for live/production environments. diff --git a/src/Umbraco.Core/HealthChecks/Checks/LiveEnvironment/RuntimeModeCheck.cs b/src/Umbraco.Core/HealthChecks/Checks/LiveEnvironment/RuntimeModeCheck.cs new file mode 100644 index 000000000000..777a8544ee00 --- /dev/null +++ b/src/Umbraco.Core/HealthChecks/Checks/LiveEnvironment/RuntimeModeCheck.cs @@ -0,0 +1,53 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using Microsoft.Extensions.Options; +using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.Services; +using Umbraco.Extensions; + +namespace Umbraco.Cms.Core.HealthChecks.Checks.LiveEnvironment; + +/// +/// Health check for the recommended production configuration for the runtime mode. +/// +[HealthCheck( + "8E31E5C9-7A1D-4ACB-A3A8-6495F3EDB932", + "Runtime Mode", + Description = "The Production Runtime Mode disables development features and checks that settings are configured optimally for production.", + Group = "Live Environment")] +public class RuntimeModeCheck : AbstractSettingsCheck +{ + private readonly IOptionsMonitor _runtimeSettings; + + /// + /// Initializes a new instance of the class. + /// + public RuntimeModeCheck(ILocalizedTextService textService, IOptionsMonitor runtimeSettings) + : base(textService) => + _runtimeSettings = runtimeSettings; + + /// + public override string ItemPath => Constants.Configuration.ConfigRuntimeMode; + + /// + public override ValueComparisonType ValueComparisonType => ValueComparisonType.ShouldEqual; + + /// + public override IEnumerable Values => new List + { + new() { IsRecommended = true, Value = RuntimeMode.Production.ToString() }, + }; + + /// + public override string CurrentValue => _runtimeSettings.CurrentValue.Mode.ToString(); + + /// + public override string CheckSuccessMessage => LocalizedTextService.Localize("healthcheck", "runtimeModeCheckSuccessMessage"); + + /// + public override string CheckErrorMessage => LocalizedTextService.Localize("healthcheck", "runtimeModeCheckErrorMessage"); + + /// + public override string ReadMoreLink => Constants.HealthChecks.DocumentationLinks.LiveEnvironment.RuntimeModeCheck; +}