Last active
November 25, 2018 01:48
-
-
Save justrjlewis/a3b4c36767a98b8b3c75 to your computer and use it in GitHub Desktop.
Run caddy server as a service: FreeBSD 10.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# PROVIDE: caddy | |
# REQUIRE: LOGIN | |
# KEYWORD: shutdown | |
# Documentation=https://caddyserver.com/docs | |
# add php-fpm to REQUIRE to run php/fastcgi processes | |
# Add the following lines to /etc/rc.conf to enable caddy: | |
# | |
# OPTION DEFAULTS | |
# | |
# caddy_enabl (bool): I set to Yes by default (26), | |
# because frankly, it's my script. :smile: | |
# caddy_user: caddysrv:caddysrv (user:group): www was unable to start | |
# caddy because it doesn't have a user/home directory. | |
# Assuming that is by design, $caddy_user serves this | |
# function [caddy start/stop/restart]. | |
# caddy_bool (bool): true | |
# caddy_email (str): No default - set to your contact info | |
# caddy_config (path): My default: `/srv/www/Caddyfile` | |
# Set to your webserver PATH | |
# Opts set in THIS file - can be set in /etc/rc.conf as well (not recommended): | |
# caddy_flags (str): -agree=true | |
# -email="[email protected]" | |
# -conf=/your/webroot/path/Caddyfile | |
# -pidfile=/path/to/var/run/caddy.pid | |
. /etc/rc.subr | |
name="caddy" | |
rcvar=caddy_enable | |
# Set defaults | |
: ${caddy_enable:="NO"} | |
: ${caddy_user="caddysrv"} | |
: ${caddy_config="/srv/www/Caddyfile"} | |
: ${caddy_email="[email protected]"} | |
: ${process_flags="-agree=true [email protected]"} | |
pidfile="/srv/var/run/${name}.pid" | |
procname="/usr/local/sbin/${name}" | |
command="/usr/sbin/daemon" | |
command_args="-cf -p ${pidfile} -u ${caddy_user} ${procname} ${process_flags}" | |
command_msg="Starting caddy..." | |
sig_stop="QUIT" | |
sig_reload="USR1" | |
start_cmd="${name}_start" | |
start_precmd="${name}_prestart" | |
start_postcmd="${name}_poststart" | |
caddy_prestart() { | |
install -o ${caddy_user} /dev/null ${pidfile} | |
} | |
caddy_start() { | |
${command} ${command_args} | |
} | |
caddy_poststart() { | |
echo ${command_msg} | |
} | |
load_rc_config "$name" | |
run_rc_command "$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# PROVIDE: caddy | |
# REQUIRE: LOGIN | |
# KEYWORD: shutdown | |
# Documentation=https://caddyserver.com/docs | |
# add php-fpm to REQUIRE to run php/fastcgi processes | |
# Add the following lines to /etc/rc.conf to enable caddy: | |
# | |
# caddy_enabl (bool): I set to Yes by default (26), | |
# because frankly, it's my script. :smile: | |
# caddy_flags (str): -agree=true | |
# -email="[email protected]" | |
# -conf=/your/webroot/path/Caddyfile | |
# caddy_user: caddysrv:caddysrv (user:group): www was unable to start | |
# caddy because it doesn't have a user/home directory. | |
# Assuming that is by design, $caddy_user serves this | |
# function [caddy start/stop/restart]. | |
# Opts that need to be set in THIS file: | |
# caddy_email (mailto): No default - set to your contact info | |
# caddy_config (path): My default: `/srv/www/Caddyfile` | |
# Set to your webserver PATH | |
. /etc/rc.subr | |
name="caddy" | |
rcvar=caddy_enable | |
load_rc_config "$name" | |
# Set defaults | |
: ${caddy_enable:="YES"} | |
: ${caddy_email="[email protected]"} | |
: ${caddy_config="/srv/www/Caddyfile"} | |
: ${caddy_flags="-agree=true -email="$caddy_email" -conf=$caddy_config"} | |
: ${caddy_user="caddysrv"} | |
pidfile="/var/run/${name}.pid" | |
sig_stop="QUIT" | |
sig_reload="USR1" | |
command="/usr/local/sbin/${name}" | |
start_cmd="${name}_start" | |
caddy_start() { | |
echo "Starting caddy server." | |
/usr/sbin/daemon -cf -p ${pidfile} -u ${caddy_user} ${command} ${caddy_flags} | |
echo "All done!" | |
} | |
run_rc_command "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment