Verify variable replacement for Windows Service?

I’m trying to verify that JSON variable replacement in my appsettings.json file was done correctly, as I am new to both Octopus Deploy and .NET Core development.

I see in the Task Log that Octopus failed to start my application as a Windows Service.

21:54:40 Info | Starting the HydratorService service
21:54:40 Info | Attempt 1 of 3 failed: Service ‘HydratorService (HydratorService)’ cannot be started due to the following error: Cannot start service HydratorService on computer ‘.’.
21:54:40 Info | Waiting for 1 seconds before retrying…
21:54:42 Info | Retrying…
21:54:42 Info | Attempt 2 of 3 failed: Service ‘HydratorService (HydratorService)’ cannot be started due to the following error: Cannot start service HydratorService on computer ‘.’.
21:54:42 Info | Waiting for 1 seconds before retrying…
21:54:43 Info | Retrying…
21:54:43 Error | Start-Service : Service ‘HydratorService (HydratorService)’ cannot be started due to the following error: Cannot start
21:54:43 Error | service HydratorService on computer ‘.’.
21:54:43 Error | At D:\APPS\DEV\DevPortalCache\2021.5.25.175222\Octopus.Features.WindowsService_BeforePostDeploy.ps1:200 char:3
21:54:43 Error | + Start-Service $psServiceName
21:54:43 Error | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21:54:43 Error | + CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service],
21:54:43 Error | ServiceCommandException
21:54:43 Error | + FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand
21:54:43 Verbose | Deleting ‘D:\APPS\DEV\DevPortalCache\2021.5.25.175222\Octopus.Features.WindowsService_BeforePostDeploy.ps1’

In my Worker Service code I have Serilog LogError calls for failure to start the service.

What I am trying to do is make sure the service start is not failing because of my incorrect usage of Octopus Deploy’s JSON variable replacement feature. I presume I have to get those Serilog statements to appear in the task log? What do I need to do to make this happen? I am also open to other means of verifying that I used JSON variable replacement correctly.

Attached is the raw task log.ServerTasks-81215.log.txt (17.8 KB)

Hi Paolo,

Thanks for getting in touch, and welcome to Octopus!

It does seem possible the service is failing to start due to an incorrect value in your appsettings.json, which could be due to the substitution Octopus is performing on it. The first thing I’d like to check is how these variables, those meant to apply to the JSON file, are defined in Octopus to rule out any possible syntax issue. Using this doc section as an example, a variable with name app:port with value 4444 will target {"app":{"port":80}} in the appsettings file and output {"app":{"port":4444}}.

What I’d suggest doing from here is turning on verbose logging temporarily, which is done by creating two variables in your project: OctopusPrintVariables and OctopusPrintVariables, both with a value of True. This will output a lot more information in the resulting task log, including every variable before and after evaluation on each step, and that should help point us in the right direction.

I look forward to hearing back!

Best regards,

Kenny

Thank you! I added the two suggested project variables. I can see the Octopus read the WorkerInterval and Serilog file output path in the verbose log. However I still cannot see if these values were successfully uses in variable replacement on the appsettings.json.

Is there a way to see what appsettings.json looks like after the variable replacement?

Attached is the raw task log with verbose output.ServerTasks-81331.log.txt (46.0 KB)