I have created a new jail, and I'm trying to install Caddy Server V2. I am able to start it manually, but if I restart the jail it doesn't start.
I have the bash file in /usr/local/etc/rc.d/caddy
The file is executable.
I have added it to the start up using sysrc caddy_enable=YES
In the terminal it will successfully start when I use service caddy start.
The bash file I am using is below. I got the file from https://www.davd.io/posts-caddy-freebsd-init-script/, and updated it for Caddy V2. Any help in figuring out why it won't start when the jail restarts would be appriciated.
I have the bash file in /usr/local/etc/rc.d/caddy
The file is executable.
I have added it to the start up using sysrc caddy_enable=YES
In the terminal it will successfully start when I use service caddy start.
The bash file I am using is below. I got the file from https://www.davd.io/posts-caddy-freebsd-init-script/, and updated it for Caddy V2. Any help in figuring out why it won't start when the jail restarts would be appriciated.
Code:
#!/bin/sh
#
# PROVIDE: caddy
# REQUIRE: networking
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable caddy:
# caddy_enable (bool): Set to "NO" by default.
# Set it to "YES" to enable caddy
#
# caddy_bin_path (str): Set to "/usr/local/bin/caddy" by default.
# Provides the path to the caddy server executable
#
# caddy_run_user (str): Set to "root" by default.
# Defines the user that caddy will run on
#
. /etc/rc.subr
name="caddy"
rcvar="${name}_enable"
load_rc_config $name
: ${caddy_enable:=no}
: ${caddy_bin_path="/usr/local/bin/caddy"}
: ${caddy_config_path="/media/caddy.json"}
: ${caddy_run_user="root"}
pidfile="/var/run/caddy.pid"
logfile="/var/log/caddy.log"
command="${caddy_bin_path} start -config ${caddy_config_path}"
start_cmd="caddy_start"
status_cmd="caddy_status"
stop_cmd="caddy_stop"
caddyserver_start() {
echo "Starting ${name}..."
/usr/sbin/daemon -u ${caddy_run_user} -c -p ${pidfile} -f ${command}
}
caddyserver_status() {
if [ -f ${pidfile} ]; then
echo "${name} is running as $(cat $pidfile)."
else
echo "${name} is not running."
return 1
fi
}
caddyserver_stop() {
if [ ! -f ${pidfile} ]; then
echo "${name} is not running."
return 1
fi
echo -n "Stopping ${name}..."
kill -KILL $(cat $pidfile) 2> /dev/null && echo "stopped"
rm -f ${pidfile}
}
run_rc_command "$1"