Running NServiceBus in a container with readOnlyRootFilesystem set to True

Hello,

I’m trying to run a .NET 6 / NServiceBus 7.7.0 application in a container with readOnlyRootFilesystem set to True. Setting the DOTNET_EnableDiagnostics environment variable to 0 made .NET runtime happy and the application runs successfully but I’m getting these NServiceBus errors / warnings at startup. Is there a configuration / setting I can apply to stop getting them?

  1. Failed to initialize the license (there’s a License.xml file in the same folder as the executable and there’s no error when the file system is read/write)
crit: NServiceBus.Features.LicenseReminder[0]
      Failed to initialize the license
      System.IO.IOException: Read-only file system : '/home/appuser/.local/share/ParticularSoftware'
         at System.IO.FileSystem.CreateDirectory(String fullPath)
         at System.IO.Directory.CreateDirectory(String path)
         at Particular.Licensing.TrialStartDateStore.GetTrialStartDate() in /_1/particular.licensing.sources/3.3.2/contentFiles/cs/any/Particular.Licensing/TrialStartDateStore.cs:line 26
         at Particular.Licensing.ActiveLicense.Find(String applicationName, LicenseSource[] licenseSources) in /_1/particular.licensing.sources/3.3.2/contentFiles/cs/any/Particular.Licensing/FindActiveLicense/ActiveLicense.cs:line 43
         at NServiceBus.LicenseManager.InitializeLicense(String licenseText, String licenseFilePath) in /_/src/NServiceBus.Core/Licensing/LicenseManager.cs:line 22
         at NServiceBus.Features.LicenseReminder.Setup(FeatureConfigurationContext context) in /_/src/NServiceBus.Core/Licensing/LicenseReminder.cs:line 22
  1. Unable to create the diagnostics output directory (I can mount an ephemeral volume to this location but I’d prefer to simply turn this diagnostics off)
warn: NServiceBus.HostStartupDiagnosticsWriter[0]
      Unable to create the diagnostics output directory. Check the attached exception for further information, or change the diagnostics directory using 'EndpointConfiguration.SetDiagnosticsPath()'.
      System.IO.IOException: Read-only file system : '/app/.diagnostics'
         at System.IO.FileSystem.CreateDirectory(String fullPath)
         at System.IO.Directory.CreateDirectory(String path)
         at NServiceBus.HostStartupDiagnosticsWriterFactory.BuildDefaultDiagnosticsWriter(Configuration configuration) in /_/src/NServiceBus.Core/Hosting/StartupDiagnostics/HostStartupDiagnosticsWriterFactory.cs:line 43

Thanks!

For anyone who may be interested - here’s the way I solved these:

  1. The license file name is case-sensitive in Linux containers! I had a file named License.xml in the app folder and the license manager ignored it. I renamed the file to license.xml (all lowercase) and the error went away.
  2. I mounted an emptyDir volume to /app/.diagnostics.

Guidance regarding diagnostics:

We do not advise turning this off as we frequently ask to share this file for support cases.

If you really want to disable it then you can do what the snippet shows at Startup diagnostics • NServiceBus • Particular Docs

endpointConfiguration.CustomDiagnosticsWriter(diagnostics => Task.CompletedTask);

Again, we would not advise this. It is highly recommended to store the diagnostic file and log files. Maybe not in the container but to a remote destination.

If you are not yet overriding logging I highly recommend using Microsoft.Extensions.Logging:

An alternative to using the diagnostics file is to write it via a logger.

– Ramon

Regarding the observed behavior. We should improve that and I’ve created an improvement issue for that:

1 Like

Thanks for the tip Ramon! I’m using NServiceBus.Extensions.Hosting package to boostrap the application so logging is already wired up. Writing diagnostics to a logger may be simpler than mounting a read/write volume to /app/.diagnostics so I’ll definitely check it out.