diff --git a/contrib/FreeBSD/README.md b/contrib/FreeBSD/README.md new file mode 100644 index 0000000000..fb03830687 --- /dev/null +++ b/contrib/FreeBSD/README.md @@ -0,0 +1,82 @@ +This folder contains `sopel` and `sopel-default.cfg` designed to be distributed by third parties such as FreeBSD. + +`sopel-default.cfg` is a default configuration file for sopel. + +The -default prefix is mandatory and will be used as a 'profile'. + +The profiles started by the service may be changed with the variable `sopel_profiles` in `/etc/rc.conf`, or with the `sysrc` command: + +```sh +sysrc sopel_profiles="profile1 profile2 profile3" +``` + +By default, the configuration directory is `/usr/local/etc`. + +For the above example, the configuration files `sopel-profile1.cfg`, `sopel-profile2.cfg`, and `sopel-profile3.cfg` must be present there. + +The service must be installed in `/usr/local/etc/rc.d`: + +```sh +cp sopel.sh /usr/local/etc/rc.d/sopel +chmod +x /usr/local/etc/rc.d/sopel +``` + +The default configuration file must be installed in the configuration directory as another profile. For example: + +```sh +cp sopel-default.cfg /usr/local/etc +``` + +That configuration has the variables `logdir`, `homedir` and `pid_dir`. + +You must create `homedir`, `logdir` and `pid_dir` directories: + +```sh +mkdir -p path/to/homedir +mkdir -p path/to/logdir +mkdir -p path/to/pid_dir +``` + +The service file has a variable named `sopel_user` (by default, the value is `sopel`). You must create that user before starting sopel. + +After creating the user for sopel, you must change the owner of the `logdir`, `pid_dir` and `homedir` directories: + +```sh +chown sopel:sopel path/to/logdir +chown sopel:sopel path/to/pid_dir +chown sopel:sopel path/to/homedir +``` + +If you want to run sopel at startup, the variable `sopel_enable` must be set to `YES`: + +```sh +sysrc sopel_enable="YES" +``` + +Now, you can run the service with the `service(8)` command, but if you want to change any options, you can do so by editing the `sopel-default.cfg` configuration file or by using `service sopel configure`. When sopel is configured, it can be started: + +```sh +service sopel start +``` + +If you want to change the python version, the variable `sopel_interpreter` must be changed. For example: + +```sh +sysrc sopel_interpreter="/usr/local/bin/python3.8" +``` + +You can set any other variable, but by default, the sopel service has many default values: + +```sh +$ egrep -E '^: \$\{sopel_.+:=.+}' sopel +: ${sopel_enable:="NO"} +: ${sopel_piddir:="/var/run/sopel"} +: ${sopel_confdir:=/usr/local/etc} +: ${sopel_flags:=--config-dir "${sopel_confdir}"} +: ${sopel_program:="/usr/local/bin/sopel"} +: ${sopel_user:=${name}} +: ${sopel_interpreter:=/usr/local/bin/python3.9} +: ${sopel_profiles:=default} +: ${sopel_prefix:=sopel-} +: ${sopel_output:=/dev/null} +``` diff --git a/contrib/FreeBSD/sopel-default.cfg b/contrib/FreeBSD/sopel-default.cfg new file mode 100644 index 0000000000..60070a8a86 --- /dev/null +++ b/contrib/FreeBSD/sopel-default.cfg @@ -0,0 +1,15 @@ +# +# IMPORTANT NOTE! +# You must delete the not_configured line in order for the bot to work, +# otherwise it will refuse to start. +[core] +nick=sopel +not_configured=True +host=irc.libera.chat +port=6697 +use_ssl=True +verify_ssl=True +owner= +logdir=/var/log/sopel +pid_dir=/var/run/sopel +homedir=/var/db/sopel diff --git a/contrib/FreeBSD/sopel.sh b/contrib/FreeBSD/sopel.sh new file mode 100755 index 0000000000..0f19b532e8 --- /dev/null +++ b/contrib/FreeBSD/sopel.sh @@ -0,0 +1,120 @@ +#!/bin/sh + +# PROVIDE: sopel +# REQUIRE: FILESYSTEM NETWORKING usr + +. /etc/rc.subr + +name="sopel" +desc="Simple, easy-to-use, open-source IRC utility bot, written in Python" +rcvar="${name}_enable" +start_cmd="sopel_start" +stop_cmd="sopel_stop" +restart_cmd="sopel_restart" +status_cmd="sopel_status" +configure_cmd="sopel_configure" +extra_commands="configure" + +load_rc_config "${name}" + +: ${sopel_enable:="NO"} +: ${sopel_piddir:="/var/run/sopel"} +: ${sopel_confdir:=/usr/local/etc} +: ${sopel_flags:=--config-dir "${sopel_confdir}"} +: ${sopel_program:="/usr/local/bin/sopel"} +: ${sopel_user:=${name}} +: ${sopel_interpreter:=/usr/local/bin/python3.9} +: ${sopel_profiles:=default} +: ${sopel_prefix:=sopel-} +: ${sopel_output:=/dev/null} + +sopel_start() +{ + local profile + + profile="$1"; shift + + echo "Starting sopel profile '${profile}'." && sleep 1 + /usr/sbin/daemon \ + -o "${sopel_output}" \ + -t "${desc}" \ + -u "${sopel_user}" \ + ${sopel_interpreter} \ + ${sopel_program} start ${sopel_flags} \ + -c "${sopel_prefix}${profile}" $@ +} + +sopel_stop() +{ + local pid pidfile profile + + profile="$1"; shift + + pidfile="${sopel_piddir}/${sopel_prefix}${sopel_prefix}${profile}.pid" + if ! [ -f "${pidfile}" ]; then + return 1 + fi + + pid=`cat ${pidfile}` + + echo "Stopping sopel profile '${profile}'." + /usr/sbin/daemon \ + -o "${sopel_output}" \ + ${sopel_interpreter} \ + ${sopel_program} stop ${sopel_flags} \ + -c "${sopel_prefix}${profile}" $@ + + wait_for_pids $pid +} + +sopel_restart() +{ + local profile + + profile="$1"; shift + + run_rc_command stop "${profile}" $@ && + sleep 1 && + run_rc_command start "${profile}" $@ +} + +sopel_status() +{ + local profile pid + + profile="$1"; shift + + pid=`check_pidfile \ + "${sopel_piddir}/${sopel_prefix}${sopel_prefix}${profile}.pid" \ + "${sopel_program}" \ + "${sopel_interpreter}"` + + if [ -n "${pid}" ]; then + echo "Sopel profile '${profile}' is running as pid ${pid}." + else + echo "Sopel profile '${profile}' is not running." + fi +} + +sopel_configure() +{ + local profile + + profile="$1"; shift + + echo "Configuring profile '${profile}'..." + + ${sopel_interpreter} \ + ${sopel_program} configure ${sopel_flags} \ + -c "${sopel_confdir}/${sopel_prefix}${profile}" $@ +} + +cmd="$1"; shift +for profile in $sopel_profiles; do + if ! [ -f "${sopel_confdir}/${sopel_prefix}${profile}.cfg" ]; then + echo "Sopel profile '${profile}' does not exist." + continue + fi + + run_rc_command "${cmd}" "${profile}" $@ +done