I followed the tutorial for practical rc.d scripting to enable caddy web server on my DO FreeBSD 10.2 droplet. It's very simple, which is probably why it's not quite working as expected. So let me start by posting my questions, then I'll show my code.
Here's my script (I couldn't use %%PREFIX%% since I didn't install it):
- The pre-commit check list says:
2.Does the file have a $FreeBSD$ tag?
-- no clue what that is...?? Google searching led to something about VLAN, but I couldn't wrap my head around what that was either, or how to apply it to my caddy.in file. - I was trying to find/think of a way to get the
service start
to run as the user rather than root, but I couldn't configure that in such a way as to work. I tried putting su in the command. One thing I didn't try, but thought of, was using some type of prestart function, but wasn't really sure where to go with that. 6.28 Says something about specifying the users and groups in the Makefile, but I wasn't clear on what to do with the whole makefile thing so I just added the caddy binary and my script file to the path and edited therc.conf
. I get that that's not exactly what was supposed to happen, but I'm not sure how to proceed. Any help here would be great. - All that being said, my service does sort of work. Bugs?
- It doesn't run in the background so nothing happens after the server starts and you can't ssh into the server without stopping it so that the OS can finish its' tasks...not exactly what I was going for.
- Again - service is running as the root user.
Here's my script (I couldn't use %%PREFIX%% since I didn't install it):
Code:
#!/bin/sh
# PROVIDE: caddy
# REQUIRE: LOGIN
# KEYWORD: shutdown
# Documentation=https://caddyserver.com/docs
# php-fpm is required if you're going 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 (19),
# because frankly, it's my script. :smile:
# caddy_config (path): Set to `/srv/www/Caddyfile` - my default.
# Set to your webserver PATH
# caddy_flags (str): -agree=true
# -conf=/your/webroot/path/Caddyfile
. /etc/rc.subr
name="caddy"
rcvar=caddy_enable
load_rc_config "$name"
: ${caddy_enable:="YES"}
: ${caddy_config="/srv/www/Caddyfile"}
: ${caddy_flags="-agree=true -conf=$caddy_config"}
command="/usr/local/sbin/${name}"
run_rc_command "$1"