Freebsd rc.d Script

Using the official asset from Github for Caddy V2 I’m struggling to get a working rc.d startup script under FreeBSD 11.4.

Here is what I have, however, when running service caddy start, the script echo’s starting caddy but caddy does not appear to actually launch. There is no process or pid for caddy.

https://pastebin.com/NaFDHXx8

        # $FreeBSD: head/net/caddy/files/caddy.in 452063 2017-10-14 12:58:24Z riggs $
#
# PROVIDE: caddy
# REQUIRE: LOGIN
# 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.
# caddy_user (user):		Set user to run caddy.
#				Default is "caddy".
# caddy_group (group):	Set group to run caddy.
#				Default is "caddy".
# caddy_conf (path):		Path to caddy configuration file.
#				Default is /usr/local/etc/caddyfile.conf

. /etc/rc.subr

name=caddy
rcvar=caddy_enable

load_rc_config $name

: ${caddy_enable:="NO"}
: ${caddy_user:="caddy"}
: ${caddy_group:="caddy"}
: ${caddy_conf:="/usr/local/etc/Caddyfile"}
: ${caddy_log:="/home/caddy/caddy.log"}
: ${caddy_env:="CADDYPATH=/home/caddy/"}
: ${caddy_https_port:="443"}
: ${caddy_http_port:="80"}

pidfile=/var/run/caddy.pid
procname="/usr/local/bin/caddy"
command="/usr/sbin/daemon"
command_args="-f -p ${pidfile} /usr/bin/env ${caddy_env} ${procname} -agree -http-port ${caddy_http_port}  -https-port ${caddy_https_port} -conf=${caddy_conf} -log=${caddy_log} ${caddy_args}"

start_precmd=caddy_startprecmd

caddy_startprecmd()
{
        if [ ! -e ${pidfile} ]; then
                install -o ${caddy_user} -g ${caddy_group} /dev/null ${pidfile};
        fi
}

run_rc_command "$1"

Please use ``` on the lines before and after your config/code when posting in the forums to use code formatting. It’s very hard to read what you wrote here without proper formatting.

That rc.d script is for Caddy v1 and uses incorrect CLI arguments; Caddy v2 has a different CLI. You’ll want to use caddy run, see the docs below:

Here’s what the systemd service looks like, for comparison:

This topic was automatically closed after 30 days. New replies are no longer allowed.