Caddy: Add a cli parameter to validate a Caddyfile

Created on 5 Jan 2017  路  9Comments  路  Source: caddyserver/caddy

At our company we are deploying caddy via Gitlab CI if someone pushes a new Caddyfile to a repository. It would help us big times if caddy had a parameter like caddy -validate /etc/Caddyfile that returns a non-zero code if something obvious (f.e. there is a syntax error) is wrong with the caddyfile. In that case the Caddyfile would not be deployed and the caddy instance would not crash.

You may ask if I could just start the caddy with the config on the ci server. This will not work since we are using let's encrypt for this config and thous caddy cant activate the privacy features and will fail to start.

feature request

Most helpful comment

This has been implemented & merged in #1344

All 9 comments

So if we implemented -validate to only parse the Caddyfile (thus reporting syntax errors), would that be sufficient?

@mholt Yes, that would be excellent.

I'll take a look at implementing this

Still working on this but the implementation is designed to be as follows

Addition of a new -validate command line parameter which should parse the caddyfile but not run the server. Also no TLS certs should be requested.

  • If there is an error in the caddyfile caddy will exit with an error as normal
  • If there is no error in the caddyfile caddy will exit with no further output.

@enko do you have any comments on the proposed implementation.

If there is no error, are there any downsides to displaying something like the following?

Caddyfile syntax validated successfully.

Just curious. 馃槃

Maybe not. But the "unixy" way of doing things is to not output anything on success.

@tobya yeah, thats what I need, just the error codes are fine.

If you can build from source this is implemented in branch issue1328d #1344

This has been implemented & merged in #1344

Was this page helpful?
0 / 5 - 0 ratings