From nobody Thu Sep 29 15:43:20 2022 X-Original-To: dev-commits-ports-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Mdd1N5XZJz4d6ZT; Thu, 29 Sep 2022 15:43:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Mdd1N51htz3y1d; Thu, 29 Sep 2022 15:43:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664466200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3pUi36vwZgjr6EpW9MAm7B8LAtOMEEoxPihflDKAYg8=; b=kWatVsZLnv6I06TJBrfPAmHM5+MaPuMVPz6hKIrNyyakDsmjsRJ/2EFYWZOJlry/+1s8iV vnEttZX8nRVXIMTulLoBYgar/HV57qLgsyx1FI28ahhSpvulK+HLnqwR5WX6oS19Z7UqbU Mvuq3ozq6ZjPWB6GbeG7sQecbXv2kxsAZUr1UT2fF/KiZjDU9EJN7UfuZM4AaLPCUxZnth yruYLHEwXLPo9wJcWnRW/U7h7WEk5uP6iv3+hWWI6B8qy2RkCmzlPZhMnXTmWGFU3n3XN8 7+PgStndbu2UKkWgdUf2NsluJIqb4AQ14mp8uxoSv+eBvOxeI2f2rTKO0E3nUA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Mdd1N43Z3zrfh; Thu, 29 Sep 2022 15:43:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 28TFhKYc027511; Thu, 29 Sep 2022 15:43:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28TFhKw3027510; Thu, 29 Sep 2022 15:43:20 GMT (envelope-from git) Date: Thu, 29 Sep 2022 15:43:20 GMT Message-Id: <202209291543.28TFhKw3027510@gitrepo.freebsd.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org From: Adam Weinberger Subject: git: 713d74907d70 - main - www/xcaddy: Add rc(8) script List-Id: Commits to the main branch of the FreeBSD ports repository List-Archive: https://lists.freebsd.org/archives/dev-commits-ports-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-ports-main@freebsd.org X-BeenThere: dev-commits-ports-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: adamw X-Git-Repository: ports X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 713d74907d70e27aa27264cbbe03e92bbca7e250 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664466200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3pUi36vwZgjr6EpW9MAm7B8LAtOMEEoxPihflDKAYg8=; b=bS7m2yaULzX3IRv30vKZ1TDxtVEeXPCYs9a3KX4RJxi1D81h5qq5c0zS/jbKY5czu+lzQr GRS2FOHhF08aUNjPGAOOElnvqczUipPz2o6UTlqHDr7n4Q9u8pOIsfwzfmwPJn43vovLuC UktyUzz4TU3CBcjtULyeTNG99Pd/O9FYJfGQb7ugzFOf4kWmHgRG6OIkTRjO4tYA4PaoP3 SPLXav8kYGJHl3jSIDZh/RzqDokA+iPMBQpBIXwrjzUIzH4FVQdHs46CYXP4T9Eg7Bymp+ Lg5O6Ohl1JWRG2Ya/72dXzlbbtahGpb2SFpIHBG+fGsaoJkeBVdt6hQ+9ZimHA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664466200; a=rsa-sha256; cv=none; b=O9hOZXD5glk3whR7eH8/9nn+WfgekV8cDew/t0pjdWDgoM5tQlXULXPKkn3BVgCLecLWjI WJO+rHbDDx8U9EZhmk01fdHSjtvk0qX5c4zX8rElwFh6cmYQgRDIzagDuqY+DJmHyriWSe zn0Wr/j/n0gpoUeWtnzc0GotiatckIXI58+IoZW0CZHQlK7BiL+IPl64eZIkYAEY9iSQGX LEuMQmVz3jydP+nOri5ZPwB3SNzxWrcILrvXfEfvGNEaDN9O+NAdssImk86go2YWoJ8sPU Td08SkdreUyTtvSK55cWqiFn3LYaZgw8gV3yp7lVlOpFOXHbrgdqSZU04k8E1A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by adamw: URL: https://cgit.FreeBSD.org/ports/commit/?id=713d74907d70e27aa27264cbbe03e92bbca7e250 commit 713d74907d70e27aa27264cbbe03e92bbca7e250 Author: Adam Weinberger AuthorDate: 2022-09-29 15:38:38 +0000 Commit: Adam Weinberger CommitDate: 2022-09-29 15:43:03 +0000 www/xcaddy: Add rc(8) script Bring in the rc(8) script from caddy to xcaddy so that xcaddy users can control caddy like an adult. Add CONFLICTS between xcaddy and caddy because they now install the same rc(8) script. There's no reason to change the install path here because, as olgeni put it, "xcaddy with plugins is more caddy than caddy". Suggested by: bdrewery Approved by: olgeni (xcaddy maintainer) --- www/caddy/Makefile | 2 + www/xcaddy/Makefile | 8 ++- www/xcaddy/files/caddy.in | 127 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+), 1 deletion(-) diff --git a/www/caddy/Makefile b/www/caddy/Makefile index 14629b7b0cbf..b2b10dce42cb 100644 --- a/www/caddy/Makefile +++ b/www/caddy/Makefile @@ -18,6 +18,8 @@ CPE_VENDOR= caddyserver USE_RC_SUBR= caddy SUB_FILES= Caddyfile.sample caddy pkg-message +CONFLICTS_INSTALL= xcaddy + PLIST_FILES= bin/${PORTNAME} \ "@sample ${ETCDIR_REL}/Caddyfile.sample" diff --git a/www/xcaddy/Makefile b/www/xcaddy/Makefile index 899a586b7f7a..3bc889dbe9db 100644 --- a/www/xcaddy/Makefile +++ b/www/xcaddy/Makefile @@ -1,7 +1,7 @@ PORTNAME= xcaddy DISTVERSIONPREFIX= v DISTVERSION= 0.3.1 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= www DIST_SUBDIR= xcaddy @@ -14,6 +14,12 @@ LICENSE_FILE= ${WRKSRC}/LICENSE USES= go:modules +USE_RC_SUBR= caddy +SUB_FILES= caddy +SUB_LIST+= CADDYDIR="${PREFIX}/etc/caddy" + +CONFLICTS_INSTALL= caddy + USE_GITHUB= yes GH_ACCOUNT= caddyserver GH_TUPLE= Masterminds:semver:v3.1.1:masterminds_semver_v3/vendor/github.com/Masterminds/semver/v3 \ diff --git a/www/xcaddy/files/caddy.in b/www/xcaddy/files/caddy.in new file mode 100644 index 000000000000..e1b137b37380 --- /dev/null +++ b/www/xcaddy/files/caddy.in @@ -0,0 +1,127 @@ +#!/bin/sh + +# PROVIDE: caddy +# REQUIRE: LOGIN DAEMON NETWORKING +# KEYWORD: shutdown + +# To enable caddy, add 'caddy_enable="YES"' to /etc/rc.conf or +# /etc/rc.conf.local + +# Optional settings: +# caddy_command (string): Full path to the caddy binary +# caddy_config (string): Full path to caddy config file +# (%%PREFIX%%/etc/caddy/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) +# +# 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 + +name=caddy +rcvar=caddy_enable +desc="Powerful, enterprise-ready, open source web server with automatic HTTPS written in Go" + +load_rc_config $name + +# Defaults +: ${caddy_enable:=NO} +: ${caddy_adapter:=caddyfile} +: ${caddy_config:="%%PREFIX%%/etc/caddy/Caddyfile"} +: ${caddy_command:="%%PREFIX%%/bin/${name}"} +: ${caddy_directory:=/var/db/caddy} +: ${caddy_extra_flags:=""} +: ${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 + +caddy_flags="--config ${caddy_config} --adapter ${caddy_adapter}" +pidfile="/var/run/${name}/${name}.pid" + +required_files="${caddy_config} ${caddy_command}" + +start_precmd="caddy_precmd" +start_cmd="caddy_start" +stop_precmd="caddy_prestop" + +# Extra Commands +extra_commands="configtest reload" +configtest_cmd="caddy_execute validate ${caddy_flags}" +reload_cmd="caddy_execute reload ${caddy_flags}" + +caddy_execute() +{ + /usr/bin/su -m "${caddy_user}" -c "${caddy_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 + if [ -e ${caddy_logfile} ]; then + /bin/chmod 644 ${caddy_logfile} + /usr/sbin/chown root:wheel ${caddy_logfile} + else + /usr/bin/install -m 644 -o root -g wheel /dev/null ${caddy_logfile} + fi +} + +caddy_start() +{ + echo -n "Starting caddy... " + /usr/bin/su -m ${caddy_user} -c "${caddy_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_prestop() +{ + local result + + echo -n "Stopping caddy... " + + result="$(caddy_execute stop 2>&1)" + if [ ${?} -eq 0 ]; then + echo "done" + exit 0 + else + if echo "${result}" | grep -q "connection refused"; then + echo "admin interface unavailable; using pidfile" + return 0 + else + echo "Error: Unable to stop caddy" + echo "Check the caddy log: ${caddy_logfile}" + return 1 + fi + fi +} + +run_rc_command "$1"