Skip to content

Regression: Caddy 2.9.0 log writer requires existing directory path #6766

@mattgarber

Description

@mattgarber

Overview

Using Caddy 2.8.4, an output log file could be specified such as output file /var/log/caddy/access.log, and Caddy would create the caddy subdirectory path in /var/log if it was missing before creating/opening the access.log file – assuming proper ownership and permissions, e.g., Caddy running as root.

Under Caddy 2.9.0, if the /var/log/caddy directory path doesn't already exist when Caddy starts, it will exit with a log writer error rather than creating the necessary containing directory for the log file:

Error: loading initial config: loading new config: setting up custom log 'log0': opening log writer using &logging.FileWriter{Filename:"/var/log/caddy/access.log", Mode:0x0, Roll:(*bool)(nil), RollSizeMB:239, RollCompress:(*bool)(nil), RollLocalTime:false, RollKeep:4, RollKeepDays:30}: open /var/log/caddy/access.log: no such file or directory

After looking through recent activity, I had a guess it might be related to the FileWriter changes (#6314) and chmod improvements within the past few days (#6761), although reproduced the same regression with v2.9.1-0.20250103220605-010cd982731b built with xcaddy against that latest commit (010cd98).

To Reproduce

Use the following two Dockerfiles (for v2.8.4 and v2.9.0) with identical Caddyfile to test the regression in behavior. (The v2.9.0 Dockerfile will require the /var/log/caddy directory to be created before Caddy starts, commented at first to show the error being thrown.)

Dockerfile (v2.8.4)

FROM caddy:2.8-alpine
 
COPY Caddyfile /etc/caddy/Caddyfile

EXPOSE 80
EXPOSE 443

Dockerfile (v2.9.0)

FROM caddy:2.9-alpine
 
COPY Caddyfile /etc/caddy/Caddyfile
#RUN mkdir /var/log/caddy

EXPOSE 80
EXPOSE 443

Dockerfile (commit 010cd98)

FROM caddy:2.9-builder AS builder
 
RUN xcaddy build 010cd982731b91bf60a3afd313bedcd01cd7ab0e


FROM caddy:2.9-alpine

COPY --from=builder /usr/bin/caddy /usr/bin/caddy
COPY Caddyfile /etc/caddy/Caddyfile
#RUN mkdir /var/log/caddy

EXPOSE 80
EXPOSE 443

Caddyfile

example.com {
    root /srv/www/example.com
    encode zstd gzip
    file_server

    log {
        output file /var/log/caddy/access.log {
            roll_size 250m
            roll_keep 4
            roll_keep_for 30d
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐞Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions