snapcraft has no per-app ulimit key and snapd owns the systemd unit, but
a process may always raise its own soft open-file limit up to the hard
one without privilege. The snap's Caddy service now does that before it
starts Caddy, every time, which is what makes it persist across
restarts and refreshes. CADDY_NOFILE may ask for a lower number; it is
capped at the hard limit, a non-number is ignored, and a failure to
raise is logged without stopping Caddy.
tests/snapCaddyNofile6552.test.cjs runs the helper in bash with a
lowered limit. It has not been run inside an installed snap here.
Thanks to xet7 !
Fixes#6552.
When upgrading from an old WeKan snap, $SNAP_COMMON/Caddyfile may still be in
Caddy v1 format, which Caddy 2 cannot parse (so caddy would fail to start).
caddy-control now runs migrate-caddyfile-v1-to-v2.sh before 'caddy run' when
caddy is enabled. It is safe: a no-op if the file already parses as Caddy 2;
otherwise it backs up the original, converts the common v1 directives (drop the
http:// scheme, 'proxy / TARGET' -> 'reverse_proxy TARGET', drop the v1
'websocket'/'transparent' presets that Caddy 2 does by default, 'gzip' ->
'encode gzip'), validates the result with 'caddy adapt', and only keeps it if
valid — falling back to the shipped Caddy 2 template otherwise, so caddy always
starts with valid config.
Thanks to xet7.