Failed to Start Caddy: unexpected end of JSON input

1. The problem I’m having:

I am attempting to start Caddy from sudo service caddy start - my home server was doing this fine on its own until this morning, when I installed a new second SSD.

Caddy simply fails to start, and as a result it appears myself and my users are not able to access the web services I host on this server.

So far, I’ve tried:

  • Reinstalling Caddy with apt
  • Checking/changing the ownership permissions of various Caddy directories (caddy is listed as the owner, which seems to be correct - chown’ing to myself seems to break it further)
  • Going over my Caddyfile for any kind of typo or obvious problems
  • Turning it Off and On Again:tm:
  • Ordering takeout and ignoring the problem

Unfortunately none of these seem to have solved the issue - I was really banking on that last one.

2. Error messages and/or full log output:

Error as it appears after running command:

kavicordi@v0x-actual:/$ sudo service caddy restart
Job for caddy.service failed because the control process exited with error code.
See "systemctl status caddy.service" and "journalctl -xeu caddy.service" for details.

Output of journalctl -xeu caddy.service:

kavicordi@v0x-actual:~$ journalctl -xeu caddy.service
Feb 12 22:01:04 v0x-actual caddy[13530]: caddy.AppDataDir=/var/lib/caddy/.local/share/caddy
Feb 12 22:01:04 v0x-actual caddy[13530]: caddy.AppConfigDir=/var/lib/caddy/.config/caddy
Feb 12 22:01:04 v0x-actual caddy[13530]: caddy.ConfigAutosavePath=/var/lib/caddy/.config/caddy/autosave.json
Feb 12 22:01:04 v0x-actual caddy[13530]: caddy.Version=v2.9.1 h1:OEYiZ7DbCzAWVb6TNEkjRcSCRGHVoZsJinoDR/n9oaY=
Feb 12 22:01:04 v0x-actual caddy[13530]: runtime.GOOS=linux
Feb 12 22:01:04 v0x-actual caddy[13530]: runtime.GOARCH=amd64
Feb 12 22:01:04 v0x-actual caddy[13530]: runtime.Compiler=gc
Feb 12 22:01:04 v0x-actual caddy[13530]: runtime.NumCPU=6
Feb 12 22:01:04 v0x-actual caddy[13530]: runtime.GOMAXPROCS=6
Feb 12 22:01:04 v0x-actual caddy[13530]: runtime.Version=go1.23.4
Feb 12 22:01:04 v0x-actual caddy[13530]: os.Getwd=/
Feb 12 22:01:04 v0x-actual caddy[13530]: LANG=en_US.UTF-8
Feb 12 22:01:04 v0x-actual caddy[13530]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
Feb 12 22:01:04 v0x-actual caddy[13530]: NOTIFY_SOCKET=/run/systemd/notify
Feb 12 22:01:04 v0x-actual caddy[13530]: HOME=/var/lib/caddy
Feb 12 22:01:04 v0x-actual caddy[13530]: LOGNAME=caddy
Feb 12 22:01:04 v0x-actual caddy[13530]: USER=caddy
Feb 12 22:01:04 v0x-actual caddy[13530]: INVOCATION_ID=881b259cc9534388a2d02fe776b05ec7
Feb 12 22:01:04 v0x-actual caddy[13530]: JOURNAL_STREAM=8:274783
Feb 12 22:01:04 v0x-actual caddy[13530]: SYSTEMD_EXEC_PID=13530
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"info","ts":1739397664.8932376,"msg":"using config from file","file":"/etc/caddy/Caddyfile"}
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"info","ts":1739397664.894278,"msg":"adapted config to JSON","adapter":"caddyfile"}
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"info","ts":1739397664.894979,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"info","ts":1739397664.8950996,"logger":"http.auto_https","msg":"server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS","server_name":"srv0","https_port":443}
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"info","ts":1739397664.8951104,"logger":"http.auto_https","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"info","ts":1739397664.895163,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0001a2000"}
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"info","ts":1739397664.8957632,"logger":"http","msg":"enabling HTTP/3 listener","addr":":443"}
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"info","ts":1739397664.895876,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"warn","ts":1739397664.8959026,"logger":"http","msg":"HTTP/2 skipped because it requires TLS","network":"tcp","addr":":80"}
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"warn","ts":1739397664.8959064,"logger":"http","msg":"HTTP/3 skipped because it requires TLS","network":"tcp","addr":":80"}
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"info","ts":1739397664.895909,"logger":"http.log","msg":"server running","name":"remaining_auto_https_redirects","protocols":["h1","h2","h3"]}
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"info","ts":1739397664.895912,"logger":"http","msg":"enabling automatic TLS certificate management","domains":["table2.v0x-actual.net","table.v0x-actual.net","files.v0x-actual.net","gm.v0x-actual.net","mc.v0x-actual.net"]}
Feb 12 22:01:04 v0x-actual caddy[13530]: {"level":"info","ts":1739397664.895914,"msg":"[INFO][FileStorage:/var/lib/caddy/.local/share/caddy] Lock for 'storage_clean' is stale (created: 2025-02-12 21:57:33.207336176 +0000 UTC, last update: 2025-02-12 22:51:12.124695454 +0000 UTC); removing then retrying: /var/lib/caddy/.local/share/caddy/locks/storage_clean.lock"}
Feb 12 22:01:04 v0x-actual caddy[13530]: Error: loading initial config: loading new config: http app module: start: finalizing automatic HTTPS: managing certificates for 5 domains: automate: manage [table2.v0x-actual.net table.v0x-actual.net files.v0x-actual.net gm.v0x-actual.net mc.v0x-actual.net]: table2.v0x-actual.net: caching certificate: decoding certificate metadata: unexpected end of JSON input
Feb 12 22:01:04 v0x-actual systemd[1]: caddy.service: Main process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ An ExecStart= process belonging to unit caddy.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 1.
Feb 12 22:01:04 v0x-actual systemd[1]: caddy.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ The unit caddy.service has entered the 'failed' state with result 'exit-code'.
Feb 12 22:01:04 v0x-actual systemd[1]: Failed to start Caddy.
░░ Subject: A start job for unit caddy.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A start job for unit caddy.service has finished with a failure.
░░ 
░░ The job identifier is 2644 and the job result is failed.

3. Caddy version:

I’m using Caddy version v2.9.1 at the present moment. It’s possible in previous attempts I was running an older version, as I have reinstalled Caddy, however no change in the error occurred.

4. How I installed and ran Caddy:

Caddy initially came pre-installed on this distribution, however I did reinstall myself while experiencing this issue.

a. System environment:

Using Ubuntu 22.04.05 LTS on this machine, CLI only.

b. Command:

I run Caddy with either of the below, depending on if the process is already running:

sudo service caddy start
sudo service caddy restart

I have the process set to typically start automatically on system start, and rarely need to manually run the command.

When attempting to reinstall, I used:

sudo apt install caddy

Which reinstalled the package with no issues or errors

c. Service/unit/compose file:

I’m fairly certain this one isn’t relevant - let me know if I should have this somewhere but I don’t recall finding this.

d. My complete Caddy config:

# Config for the host name

table.v0x-actual.net {
        # PROXY ALL REQUESTS TO PORT 30000
        reverse_proxy localhost:30000
        encode zstd gzip
}

table2.v0x-actual.net {
        # PROXY ALL REQUESTS TO PORT 30001
        reverse_proxy localhost:30001
        encode zstd gzip
}

gm.v0x-actual.net {
        # PROXY ALL REQUESTS TO PORT 30002
        reverse_proxy localhost:30002
        encode zstd gzip
}

files.v0x-actual.net {
        reverse_proxy localhost:20
}

mc.v0x-actual.net {
        reverse_proxy localhost:25565
}

Top three lines are the web service’s addresses and the destination ports, then FTP access to the server. I will not be justifying my minecraft server, but it is, admittedly, the least important item here.

5. Links to relevant resources:

I’ve checked the following and tried seeing if any of them assisted. Unfortunately I don’t think they’re what I’m looking for. There’s more, but I’m still a new user, so have the four that had the most in common with what I’m seeing.

Delete this dir /var/lib/caddy/.local/share/caddy then start Caddy. Older version of Caddy (older than 2.9.0) didn’t do atomic writes optimally and may cause certificate writing corruption, which you experienced. Deleting the directory will prompt Caddy to get new certificates and write them properly.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.