Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 28 Mar 2021 19:34:03 +0000 (UTC)
From:      Adam Weinberger <adamw@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r569408 - in head: . www/caddy www/caddy/files
Message-ID:  <202103281934.12SJY3rw047810@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: adamw
Date: Sun Mar 28 19:34:02 2021
New Revision: 569408
URL: https://svnweb.freebsd.org/changeset/ports/569408

Log:
  www/caddy: Change all caddy runtime locations
  
  Thanks to work by scf, the caddy rc(8) script has been completely
  rewritten and substantially improved, though this necessitated
  changing all runtime locations.
  
  Most importantly:
  - The runtime log now lives in /var/log/caddy/ instead of /var/log,
    so that the logdir can be null-mounted
  
  - Automatic SSL certs are now stored in /var/db/caddy/data/caddy,
    instead of /root/.local/share/caddy
  
  Caddy uses freedesktop.org's XDG base dir specification, which
  conflicts quite spectacularly with FreeBSD's hier(7). The most
  sensible thing to do was to put the runtime data stores into
  /var/db/caddy, though XDG needs XDG_DATA_HOME and XDG_CONFIG_HOME
  to be separate dirs and caddy will create a .../caddy subdir in
  each of them.

Added:
  head/www/caddy/files/pkg-message.in   (contents, props changed)
Modified:
  head/UPDATING
  head/www/caddy/Makefile
  head/www/caddy/files/Caddyfile.sample.in
  head/www/caddy/files/caddy.in

Modified: head/UPDATING
==============================================================================
--- head/UPDATING	Sun Mar 28 19:31:00 2021	(r569407)
+++ head/UPDATING	Sun Mar 28 19:34:02 2021	(r569408)
@@ -5,6 +5,24 @@ they are unavoidable.
 You should get into the habit of checking this file for changes each time
 you update your ports collection, before attempting any port upgrades.
 
+20210328:
+  AFFECTS: users of www/caddy
+  AUTHOR: adamw@FreeBSD.org
+
+  The default locations for caddy runtime files have changed.
+
+  - Caddy's runtime log is now /var/log/caddy/caddy.log
+    (was /var/log/caddy.log)
+
+  - Automatic SSL certs are now stored in /var/db/caddy/data/caddy
+    (was /root/.local/share/caddy)
+
+  - Configuration autosaves are now stored in /var/db/caddy/config/caddy
+    (was /root/.config/caddy)
+
+  You can change these defaults. See /usr/local/etc/rc.d/caddy for the
+  list of settings.
+
 20210322:
   AFFECTS: users of net/wireguard
   AUTHOR: decke@FreeBSD.org

Modified: head/www/caddy/Makefile
==============================================================================
--- head/www/caddy/Makefile	Sun Mar 28 19:31:00 2021	(r569407)
+++ head/www/caddy/Makefile	Sun Mar 28 19:34:02 2021	(r569408)
@@ -4,6 +4,7 @@
 PORTNAME=	caddy
 DISTVERSIONPREFIX=	v
 DISTVERSION=	2.3.0
+PORTREVISION=	1
 CATEGORIES=	www
 DIST_SUBDIR=	caddy
 
@@ -19,7 +20,7 @@ USES=		go:modules
 USE_RC_SUBR=	caddy
 GO_TARGET=	./cmd/caddy
 
-SUB_FILES=	caddy Caddyfile.sample
+SUB_FILES=	Caddyfile.sample caddy pkg-message
 
 PLIST_FILES=	bin/${PORTNAME} \
 		"@sample ${ETCDIR_REL}/Caddyfile.sample"

Modified: head/www/caddy/files/Caddyfile.sample.in
==============================================================================
--- head/www/caddy/files/Caddyfile.sample.in	Sun Mar 28 19:31:00 2021	(r569407)
+++ head/www/caddy/files/Caddyfile.sample.in	Sun Mar 28 19:34:02 2021	(r569408)
@@ -1,25 +1,35 @@
 # The Caddyfile is an easy way to configure your Caddy web server.
 #
-# Unless the file starts with a global options block, the first
-# uncommented line is always the address of your site.
-#
 # To use your own domain name (with automatic HTTPS), first make
 # sure your domain's A/AAAA DNS records are properly pointed to
 # this machine's public IP, then replace the line below with your
 # domain name.
-localhost
 
-# Set this path to your site's directory.
-root * %%WWWDIR%%
+# Unless the file starts with a global options block, the first
+# uncommented line is always the address of your site.
+#
+localhost {
+		# Set this path to your site's directory:
+		root * %%WWWDIR%%
 
-# Enable the static file server.
-file_server
+		# Enable the static file server:
+		file_server
 
-# Another common task is to set up a reverse proxy:
-# reverse_proxy localhost:8080
+		# Set up a reverse proxy:
+		# reverse_proxy localhost:8080
 
-# Or serve a PHP site through php-fpm:
-# php_fastcgi localhost:9000
+		# Serve a PHP site through php-fpm:
+		# php_fastcgi localhost:9000
+
+		# Enable logging:
+		log {
+				output file /var/log/caddy/access.log
+				# Caddy's structured log format:
+				format json
+				# Or, for Common Log Format:
+				# format single_field common_log
+		}
+}
 
 # Caddy will automatically obtain ACME certs for domains
 # example.com {

Modified: head/www/caddy/files/caddy.in
==============================================================================
--- head/www/caddy/files/caddy.in	Sun Mar 28 19:31:00 2021	(r569407)
+++ head/www/caddy/files/caddy.in	Sun Mar 28 19:34:02 2021	(r569408)
@@ -7,15 +7,28 @@
 # REQUIRE: LOGIN DAEMON NETWORKING
 # KEYWORD: shutdown
 
-# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
-# to enable this service:
-# caddy_enable (bool):   Set to NO by default. Set it to YES to enable caddy.
+# To enable caddy, add 'caddy_enable="YES"' to /etc/rc.conf or
+# /etc/rc.conf.local
+
+# Optional settings:
+# caddy_config (string):      Full path to caddy config file
+#                             (%%ETCDIR%%/Caddyfile)
+# caddy_adapter (string):     Config adapter type (caddyfile)
+# caddy_directory (string):   Root for caddy storage (ACME certs, etc.)
+#                             (/var/db/caddy)
+# caddy_extra_flags (string): Extra flags passed to caddy start
+# caddy_logdir (string):      Where caddy logs are stored
+#                             (/var/log/caddy)
+# caddy_logfile (string):     Location of process log (${caddy_logdir}/caddy.log)
+#                             This is for startup/shutdown/error messages.
+#                             To create an access log, see:
+#                             https://caddyserver.com/docs/caddyfile/directives/log
+# caddy_user (user):          User to run caddy (root)
+# caddy_group (group):        Group to run caddy (wheel)
 #
-# caddy_config (string):      (Optional) Full path to caddy config file
-# caddy_adapter (string):     (Optional) Adapter type if the configuration is not in caddyfile format
-# caddy_extra_flags (string): (Optional) Flags passed to caddy start
-# caddy_logfile (string):     Location of process log. This is for startup/shutdown/error messages.
-#                             To create an access log, see https://caddyserver.com/docs/caddyfile/directives/log
+# This script will honor XDG_CONFIG_HOME/XDG_DATA_HOME. Caddy will create a
+# .../caddy subdir in each of those. By default, they are subdirs of /var/db/caddy.
+# See https://caddyserver.com/docs/conventions#data-directory
 
 . /etc/rc.subr
 
@@ -27,23 +40,73 @@ load_rc_config $name
 
 # Defaults
 : ${caddy_enable:=NO}
-: ${caddy_config:=%%ETCDIR%%/Caddyfile}
 : ${caddy_adapter:=caddyfile}
+: ${caddy_config:=%%ETCDIR%%/Caddyfile}
+: ${caddy_directory:=/var/db/caddy}
 : ${caddy_extra_flags:=""}
-: ${caddy_logfile="/var/log/caddy.log"}
+: ${caddy_logdir:="/var/log/${name}"}
+: ${caddy_logfile:="${caddy_logdir}/${name}.log"}
+: ${caddy_user:="root"}
+: ${caddy_group:="wheel"}
 
+# Config and base directories
+: ${XDG_CONFIG_HOME:="${caddy_directory}/config"}
+: ${XDG_DATA_HOME:="${caddy_directory}/data"}
+export XDG_CONFIG_HOME XDG_DATA_HOME
+
 command="%%PREFIX%%/bin/${name}"
 caddy_flags="--config ${caddy_config} --adapter ${caddy_adapter}"
-pidfile="/var/run/${name}.pid"
+pidfile="/var/run/${name}/${name}.pid"
 
 required_files="${caddy_config} ${command}"
 
+start_precmd="caddy_precmd"
+start_cmd="caddy_start"
+stop_cmd="caddy_stop"
+
 # Extra Commands
 extra_commands="configtest reload"
+configtest_cmd="caddy_command validate ${caddy_flags}"
+reload_cmd="caddy_command reload ${caddy_flags}"
 
-configtest_cmd="${command} validate ${caddy_flags}"
-reload_cmd="${command} reload ${caddy_flags}"
-start_cmd="${command} start ${caddy_flags} ${caddy_extra_flags} --pidfile ${pidfile} >> ${caddy_logfile} 2>&1"
-stop_cmd="${command} stop"
+caddy_command()
+{
+	/usr/bin/su -m "${caddy_user}" -c "${command} $*"
+}
+
+caddy_precmd()
+{
+	# Create required directories and set permissions
+	/usr/bin/install -d -m 755 -o "${caddy_user}" -g "${caddy_group}" ${caddy_directory}
+	/usr/bin/install -d -m 700 -o "${caddy_user}" -g "${caddy_group}" ${caddy_directory}/config
+	/usr/bin/install -d -m 700 -o "${caddy_user}" -g "${caddy_group}" ${caddy_directory}/data
+	/usr/bin/install -d -m 755 -o "${caddy_user}" -g "${caddy_group}" ${caddy_logdir}
+	/usr/bin/install -d -m 700 -o "${caddy_user}" -g "${caddy_group}" /var/run/caddy
+}
+
+caddy_start()
+{
+	echo -n "Starting caddy... "
+	/usr/bin/su -m ${caddy_user} -c "${command} start ${caddy_flags} \
+		${caddy_extra_flags} --pidfile ${pidfile}" >> ${caddy_logfile} 2>&1
+	if [ $? -eq 0 ] && ps -ax -o pid | grep -q "$(cat ${pidfile})"; then
+		echo "done"
+		echo "Log: ${caddy_logfile}"
+	else
+		echo "Error: Caddy failed to start"
+		echo "Check the caddy log: ${caddy_logfile}"
+	fi
+}
+
+caddy_stop()
+{
+	echo -n "Stopping caddy... "
+	if caddy_command stop; then
+		echo "done"
+	else
+		echo "Error: Unable to stop caddy"
+		echo "Check the caddy log: ${caddy_logfile}"
+	fi
+}
 
 run_rc_command "$1"

Added: head/www/caddy/files/pkg-message.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/www/caddy/files/pkg-message.in	Sun Mar 28 19:34:02 2021	(r569408)
@@ -0,0 +1,41 @@
+[
+{
+  type: install
+  message: <<INSTALL
+To enable caddy:
+
+- Edit %%ETCDIR%%/Caddyfile
+  See https://caddyserver.com/docs/
+- Add caddy_enable="YES" to /etc/rc.conf
+
+%%PREFIX%%/etc/rc.d/caddy has the following defaults:
+
+- Server log: /var/log/caddy/caddy.log
+  (runtime messages, NOT an access.log)
+- Automatic SSL certificate storage: /var/db/caddy/data/caddy/
+- Runs as root:wheel (you can run as another user, like www,
+  but caddy will be unable to bind to low-numbered ports,
+  including 80 and 443)
+
+INSTALL
+}
+{
+  type: upgrade
+  maximum_version: 2.3.0
+  message: <<UPGRADE
+The default locations for caddy runtime files have changed!
+
+- Caddy's runtime log is now /var/log/caddy/caddy.log
+  (was /var/log/caddy.log)
+
+- Automatic SSL certs are now stored in /var/db/caddy/data/caddy
+  (was /root/.local/share/caddy)
+
+- Configuration autosaves are now stored in /var/db/caddy/config/caddy
+  (was /root/.config/caddy)
+
+You can change these defaults. See %%PREFIX%%/etc/rc.d/caddy
+
+UPGRADE
+}
+]



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103281934.12SJY3rw047810>