Can't install Beta17 as a Windows service using NSSM

1. My Caddy version (caddy version):

v2.0.0-beta.17 h1:x+Ur3uX83j+STerOWsrLDlknXe7z71VnO5xD+H2OwAw=

2. How I run Caddy:

nssm install caddy2 C:/appl/caddy2_beta17_windows_amd64/caddy2_beta17_windows_amd64.exe run --resume

a. System environment:

Windows 10 Pro

b. Command:

nssm install caddy2 C:/appl/caddy2_beta17_windows_amd64/caddy2_beta17_windows_amd64.exe run --resume

c. Service/unit/compose file:

N/A

d. My complete Caddyfile or JSON config:

{
	"logging": {
		"sink": {
			"writer": {
				"output": "file",
				"filename": "C:/appl/caddy2_beta17_windows_amd64/logs/unstructured.log",
				"roll": false,
				"roll_size_mb": 0,
				"roll_gzip": false,
				"roll_local_time": false,
				"roll_keep": 0,
				"roll_keep_days": 0
			}
		},
		"logs": {
			"default": {
				"writer": {
					"output": "file",
					"filename": "C:/appl/caddy2_beta17_windows_amd64/logs/structured.log",
					"roll": false,
					"roll_size_mb": 0,
					"roll_gzip": false,
					"roll_local_time": false,
					"roll_keep": 0,
					"roll_keep_days": 0
				}
			}
		}
	},
	"apps": {
		"http": {
			"servers": {
				"srv0": {
					"listen": [
						":443"
					],
					"routes": [
						{
							"match": [
								{
									"host": [
										"jenkins.xxxxxx.co.uk"
									]
								}
							],
							"handle": [
								{
									"handler": "subroute",
									"routes": [
										{
											"handle": [
												{
													"handler": "reverse_proxy",
													"headers": {
														"request": {
															"set": {
																"Host": [
																	"{http.request.host}"
																],
																"X-Forwarded-For": [
																	"{http.request.remote.host}"
																],
																"X-Forwarded-Proto": [
																	"{http.request.scheme}"
																],
																"X-Real-Ip": [
																	"{http.request.remote.host}"
																]
															}
														}
													},
													"upstreams": [
														{
															"dial": "192.168.0.100:8080"
														}
													]
												}
											]
										}
									]
								}
							],
							"terminal": true
						},
						{
							"match": [
								{
									"host": [
										"nzbget.xxxxxx.co.uk"
									]
								}
							],
							"handle": [
								{
									"handler": "subroute",
									"routes": [
										{
											"handle": [
												{
													"handler": "reverse_proxy",
													"headers": {
														"request": {
															"set": {
																"Host": [
																	"{http.request.host}"
																],
																"X-Forwarded-For": [
																	"{http.request.remote.host}"
																],
																"X-Forwarded-Proto": [
																	"{http.request.scheme}"
																],
																"X-Real-Ip": [
																	"{http.request.remote.host}"
																]
															}
														}
													},
													"upstreams": [
														{
															"dial": "192.168.0.100:6789"
														}
													]
												}
											]
										}
									]
								}
							],
							"terminal": true
						},
						{
							"match": [
								{
									"host": [
										"sonarr.xxxxxx.co.uk"
									]
								}
							],
							"handle": [
								{
									"handler": "subroute",
									"routes": [
										{
											"handle": [
												{
													"handler": "reverse_proxy",
													"headers": {
														"request": {
															"set": {
																"Host": [
																	"{http.request.host}"
																],
																"X-Forwarded-For": [
																	"{http.request.remote.host}"
																],
																"X-Forwarded-Proto": [
																	"{http.request.scheme}"
																],
																"X-Real-Ip": [
																	"{http.request.remote.host}"
																]
															}
														}
													},
													"upstreams": [
														{
															"dial": "192.168.0.100:8989"
														}
													]
												}
											]
										}
									]
								}
							],
							"terminal": true
						},
						{
							"match": [
								{
									"host": [
										"radarr.xxxxxx.co.uk"
									]
								}
							],
							"handle": [
								{
									"handler": "subroute",
									"routes": [
										{
											"handle": [
												{
													"handler": "reverse_proxy",
													"headers": {
														"request": {
															"set": {
																"Host": [
																	"{http.request.host}"
																],
																"X-Forwarded-For": [
																	"{http.request.remote.host}"
																],
																"X-Forwarded-Proto": [
																	"{http.request.scheme}"
																],
																"X-Real-Ip": [
																	"{http.request.remote.host}"
																]
															}
														}
													},
													"upstreams": [
														{
															"dial": "192.168.0.100:7878"
														}
													]
												}
											]
										}
									]
								}
							],
							"terminal": true
						},
						{
							"match": [
								{
									"host": [
										"nexus.xxxxxx.co.uk"
									]
								}
							],
							"handle": [
								{
									"handler": "subroute",
									"routes": [
										{
											"handle": [
												{
													"handler": "reverse_proxy",
													"headers": {
														"request": {
															"set": {
																"Host": [
																	"{http.request.host}"
																],
																"X-Forwarded-For": [
																	"{http.request.remote.host}"
																],
																"X-Forwarded-Proto": [
																	"{http.request.scheme}"
																],
																"X-Real-Ip": [
																	"{http.request.remote.host}"
																]
															}
														}
													},
													"upstreams": [
														{
															"dial": "192.168.0.100:8081"
														}
													]
												}
											]
										}
									]
								}
							],
							"terminal": true
						},
						{
							"match": [
								{
									"host": [
										"infa.xxxxxx.co.uk"
									]
								}
							],
							"handle": [
								{
									"handler": "subroute",
									"routes": [
										{
											"handle": [
												{
													"handler": "reverse_proxy",
													"headers": {
														"request": {
															"set": {
																"Host": [
																	"{http.request.host}"
																],
																"X-Forwarded-For": [
																	"{http.request.remote.host}"
																],
																"X-Forwarded-Proto": [
																	"{http.request.scheme}"
																],
																"X-Real-Ip": [
																	"{http.request.remote.host}"
																]
															}
														}
													},
													"upstreams": [
														{
															"dial": "192.168.0.10:8080"
														}
													]
												}
											]
										}
									]
								}
							],
							"terminal": true
						}
					]
				}
			}
		},
		"tls": {
			"automation": {
				"policies": [
					{
						"management": {
							"email": "xxxxxx@googlemail.com",
							"module": "acme"
						}
					}
				]
			}
		}
	}
}

3. The problem I’m having:

I’m currently using NSSM to install Caddy2 as a Windows Service. It worked fine on Beta15.

The service installs fine. However, on Beta 17, when I try and start the service, a generic “The service failed to start” message is produced. Of course, I can’t seem to find any logs.

4. Error messages and/or full log output:

N/A

5. What I already tried:

I’ve run the exact same command from the command line, and that works :-

C:/appl/caddy2_beta17_windows_amd64/caddy2_beta17_windows_amd64.exe run --resume

However, this uses a different profile to the windows service.

The windows service profile is :-

C:\Windows\System32\config\systemprofile\AppData\Roaming\Caddy

I guess my question is, are there any logs written anywhere that would help me determine what’s going wrong?

6. Links to relevant resources:

I think you can configure nssm to write stdout and stderr to file. Try doing that to see what Caddy is logging

Edit: found my list of commands I saved for nssm

.\nssm.exe set caddy AppStdout C:\Users\lavof\Documents\caddy\stdout.log
.\nssm.exe set caddy AppStderr C:\Users\lavof\Documents\caddy\stderr.log

Thanks! That pointed me in the right direction. I was seeing this in the logs :-

run: loading initial config: loading new config: loading http app module: provision http: getting tls app: loading tls app module: decoding module config: tls: json: unknown field “management”

So, it looks like my JSON file wasn’t correct in the new version. I then deleted my profile completely, and let it re-create via a Caddy file. This then worked.

Looking at the new generated JSON file… it looks like the “management” is replaced by “issuer” in Beta17.

So, all good and working.

Thanks for your help.

2 Likes

Oops, that was one minor (breaking) change I made in beta 17, sorry! Not many people use the JSON directly, so I didn’t know how many people it would affect.

That field name changed to issuer. https://caddyserver.com/docs/json/apps/tls/#automation/policies/issuer