geomyidae

A small C-based gopherd. (gopher://bitreich.org/1/scm/geomyidae)
git clone git://r-36.net/geomyidae
Log | Files | Refs | README | LICENSE

commit b26c0644c0b0badec69870e4b92da4e0b4225b31
parent 098b3ed375acbd86cba0dff419cd954160cb4a9e
Author: Nico Sonack <nsonack@herrhotzenplotz.de>
Date:   Fri,  5 Jul 2024 17:51:17 +0200

rc.d: clean up and update FreeBSD rc script for easier configuration

I was working on a Ports Makefile and looked for a rc script for
geomyidae. The one distributed in the source tarball seemed very
out-of-date and contained anti-patterns regarding the rc system in
FreeBSD.

Basically I went in and made it configurable through rc.conf which
is the central place for FreeBSD's rc configuration. I also updated
variable names such that they align with the patterns of rc.subr.

The reason for the change is simple: you don't want to edit the
files installed from ports/pkg because if you update they get
overwritten and all your configuration is lost.

Documentation for the configuration variables are in the comments
in the rc script.

I don't know if the TLS stuff works as I haven't configured it (and
don't need it atm). Everything else works fine on a FreeBSD
14.1-RELEASE-p2 amd64 box.

Signed-off-by: Christoph Lohmann <20h@r-36.net>

Diffstat:
Mrc.d/FreeBSD.rc.d | 116+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 72 insertions(+), 44 deletions(-)

diff --git a/rc.d/FreeBSD.rc.d b/rc.d/FreeBSD.rc.d @@ -1,61 +1,89 @@ #!/bin/sh # PROVIDE: geomyidae -# REQUIRE: DAEMON +# REQUIRE: NETWORKING SERVERS DAEMON # BEFORE: LOGIN # KEYWORD: shutdown - +# +# Add the following lines to /etc/rc.conf to enable this service +# +# geomyidae_enable (bool): Set to NO by default. +# Set to YES to enable geomyidae +# geomyidae_flags (string): Additional command line options to +# pass to geomyidae(8). +# geomyidae_user (string): Set to the user to run geomyidae as +# Default is "geomyidae" +# geomyidae_group (string): Set to the group to run geomyidae as +# Default is "geomyidae" +# geomyidae_htdocs (string): Directory to server files from +# Default is "/var/gopher" +# geomyidae_logfile (string): File to use as a logfile +# Default is "/var/log/gopherlog" +# geomyidae_bindhost (string): IP Address to bind to +# Default is all addresses +# geomyidae_port (int): Port to listen on +# Default is 70 +# geomyidae_sport (int): Port to display within base directory +# Default is 70 +# geomyidae_keyfile (string): Path to private key in case TLS support is desired +# Default is empty +# geomyidae_certfile (string): Path to public key in case TLS support is desired +# Default is empty +# +# NOTE: You need to install geomyidae setuid root:wheel for this +# to work when listening on priviledged ports. +# +# Create users and group accordingly, e.g.: +# +# # pw groupadd geomyidae -g 542 +# # pw useradd geomyidae -g geomyidae -u 542 -s /usr/sbin/nologin -d /nonexistent +# +# Create logfile, pidfile and htdocs: +# +# # mkdir /var/gopher +# # touch /var/run/geomyidae.pid +# # touch /var/log/gopherlog +# # chown geomyidae:geomyidae /var/gopher /var/run/geomyidae.pid /var/log/gopherlog . /etc/rc.subr name=geomyidae -rcvar=$name +rcvar=geomyidae_enable -command="/usr/local/bin/$name" +load_rc_config $name -geomyidae_enable=${geomyidae_enable:-"NO"} +: ${geomyidae_enable:="NO"} +: ${geomyidae_user:="geomyidae"} +: ${geomyidae_group:="geomyidae"} +: ${geomyidae_flags:=""} +: ${geomyidae_htdocs:="/var/gopher"} +: ${geomyidae_logfile:="/var/log/gopherlog"} +: ${geomyidae_bindhost:=""} +: ${geomyidae_host:="localhost"} +: ${geomyidae_port:="70"} +: ${geomyidae_sport:="70"} +: ${geomyidae_command:="/usr/local/bin/geomyidae"} +: ${geomyidae_certfile:=""} +: ${geomyidae_keyfile:=""} -##################################################### -# Geomyidae Options Section - "?" => geomyidae(8) # -# Uncomment & define options (defaults are shown) # -##################################################### -# -#LOGFILE="-l /var/log/gopherlog" -#LOGLEVEL="-v 7" -#HTDOCS="-b /var/gopher" -#PORT="-p 70" -#SPORT="-o 70" -#USR="-u $USER" -#GRP="-g $GROUP" -#HOST="-h localhost" -#IP="-i 127.0.0.1" - -###################################################### -# Next, add all DEFINED options to command_args= # -###################################################### -# -#command_args="$LOGFILE $LOGLEVEL $HTDOCS $PORT $SPORT $USR $GRP $HOST $IP" -#command_args="" +pidfile=/var/run/geomyidae.pid +procname="${geomyidae_command}" +command="/usr/sbin/daemon" +command_args="-S -T geomyidae -m 3 -f -p ${pidfile} ${geomyidae_command} -d -l ${geomyidae_logfile} \ + -b ${geomyidae_htdocs} -p ${geomyidae_port} -o ${geomyidae_sport} \ + -u ${geomyidae_user} -g ${geomyidae_group} -h ${geomyidae_host}" +# Append bindhost if set +[ ! -z "${geomyidae_bindhost}" ] && command_args="${command_args} -i ${geomyidae_bindhost}" -###################################################### -# Uncomment this section if a PID file is desired # -###################################################### +# TLS setup +[ ! -z "${geomyidae_keyfile}" -a ! -z "${geomyidae_certfile}" ] && \ + command_args="${command_args} -t ${geomyidae_keyfile} ${geomyidae_certfile}" -#pidfile="/var/run/${name}.pid" -#start_cmd="geomyidae_start" -# -#geomyidae_start() -#{ -# echo "Starting $name" -# $command $command_args -# pgrep -n $name > $pidfile -#} - -###################################################### -# Lastly, add the following to /etc/rc.conf: # -# "geomyidae=YES" (without the quotes) # -###################################################### +# Lastly append flags by user +command_args="${command_args} ${geomyidae_flags}" + +required_files="${pidfile} ${geomyidae_logfile}" +required_dirs="${geomyidae_htdocs}" -load_rc_config $name run_rc_command "$1"