From 740ee63169fc92b21b18cc56e809747b5a8eff04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Daniel=20Colmenares=20Oviedo?= Date: Mon, 25 Jul 2022 17:13:25 -0400 Subject: [PATCH 01/10] Add FreeBSD service --- contrib/FreeBSD/README | 46 ++++++++++++ contrib/FreeBSD/sopel | 120 ++++++++++++++++++++++++++++++ contrib/FreeBSD/sopel-default.cfg | 26 +++++++ 3 files changed, 192 insertions(+) create mode 100644 contrib/FreeBSD/README create mode 100755 contrib/FreeBSD/sopel create mode 100644 contrib/FreeBSD/sopel-default.cfg diff --git a/contrib/FreeBSD/README b/contrib/FreeBSD/README new file mode 100644 index 0000000000..9c0aac158f --- /dev/null +++ b/contrib/FreeBSD/README @@ -0,0 +1,46 @@ +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 may be changed with the variable `sopel_profiles` in `/etc/rc.conf`. For example: + +```sh +sysrc sopel_profiles="profile1 profile2 profile3" +``` + +The configuration files should be `${sopel_confdir}/${sopel_prefix}profile1.cfg`, `${sopel_confdir}/${sopel_prefix}profile2.cfg` and `${sopel_confdir}/${sopel_prefix}profile3.cfg`. The variable `sopel_confdir` is the default configuration directory (by default `/usr/local/etc`). `sopel_prefix`is the prefix for all files (by default `sopel-`). + +The service must be installed in `/usr/local/etc/rc.d`: + +```sh +cp sopel /usr/local/etc/rc.d +chmod +x /usr/local/etc/rc.d/sopel +``` + +The default configuration file must be installed in ${sopel_confdir}. For example: + +```sh +cp sopel-default.cfg /usr/local/etc +``` + +If you want to run sopel at startup, the variable `sopel_enable` must be set to `YES`: + +```sh +sysrc sopel_enable="YES" +``` + +If you want to change the python version, the variable `sopel_interpreter` (by default `/usr/local/bin/python3.9`) must be changed. + +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} +``` \ No newline at end of file diff --git a/contrib/FreeBSD/sopel b/contrib/FreeBSD/sopel new file mode 100755 index 0000000000..0f19b532e8 --- /dev/null +++ b/contrib/FreeBSD/sopel @@ -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 diff --git a/contrib/FreeBSD/sopel-default.cfg b/contrib/FreeBSD/sopel-default.cfg new file mode 100644 index 0000000000..0da5cc5487 --- /dev/null +++ b/contrib/FreeBSD/sopel-default.cfg @@ -0,0 +1,26 @@ +# +# IMPORTANT NOTES! +# You must delete the not_configured line in order for the bot to work, +# otherwise it will refuse to start. +# +# You must create homedir. Sopel should create the others directories: +# mkdir -p $homedir +# The service file has a variable called 'sopel_user'. This user name +# must exist. After creating the user, the owner of the logdir, +# pid_dir and homedir directories must be changed. By default, +# the value is 'sopel': +# chown sopel:sopel $logdir +# chown sopel:sopel $pid_dir +# chown sopel:sopel $homedir +# +[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 From 5ef709ffa258bc9d8657cbb827c8ddcf2d9e8bab Mon Sep 17 00:00:00 2001 From: DtxdF Date: Mon, 25 Jul 2022 21:47:17 -0400 Subject: [PATCH 02/10] Add trailing newline --- contrib/FreeBSD/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/FreeBSD/README b/contrib/FreeBSD/README index 9c0aac158f..262bad32bd 100644 --- a/contrib/FreeBSD/README +++ b/contrib/FreeBSD/README @@ -43,4 +43,4 @@ $ egrep -E '^: \$\{sopel_.+:=.+}' sopel : ${sopel_profiles:=default} : ${sopel_prefix:=sopel-} : ${sopel_output:=/dev/null} -``` \ No newline at end of file +``` From 7a19afa33343f2ceb3b557fee0724abd78608f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Daniel=20Colmenares=20Oviedo?= Date: Tue, 26 Jul 2022 10:38:21 -0400 Subject: [PATCH 03/10] Rename README to README.md --- contrib/FreeBSD/{README => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contrib/FreeBSD/{README => README.md} (100%) diff --git a/contrib/FreeBSD/README b/contrib/FreeBSD/README.md similarity index 100% rename from contrib/FreeBSD/README rename to contrib/FreeBSD/README.md From 02c98fcd782836796f5a437ee539877795f08a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Daniel=20Colmenares=20Oviedo?= Date: Tue, 26 Jul 2022 11:31:04 -0400 Subject: [PATCH 04/10] Improve the README to make it more concise. * Delete parse variables in the docs * Reduce long lines to keep between 80-120 chars --- contrib/FreeBSD/README.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/contrib/FreeBSD/README.md b/contrib/FreeBSD/README.md index 262bad32bd..296dbcbfd3 100644 --- a/contrib/FreeBSD/README.md +++ b/contrib/FreeBSD/README.md @@ -1,12 +1,20 @@ -This folder contains sopel and sopel-default.cfg designed to be distributed by third parties such as FreeBSD. +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 may be changed with the variable `sopel_profiles` in `/etc/rc.conf`. For example: +`sopel-default.cfg` is a default configuration file for sopel. + +The -default prefix is mandatory and will be used as a 'profile'. + +The profiles may be changed with the variable `sopel_profiles` in `/etc/rc.conf`. For example: ```sh sysrc sopel_profiles="profile1 profile2 profile3" ``` -The configuration files should be `${sopel_confdir}/${sopel_prefix}profile1.cfg`, `${sopel_confdir}/${sopel_prefix}profile2.cfg` and `${sopel_confdir}/${sopel_prefix}profile3.cfg`. The variable `sopel_confdir` is the default configuration directory (by default `/usr/local/etc`). `sopel_prefix`is the prefix for all files (by default `sopel-`). +By default, the configuration directory is `/usr/local/etc`. + +The `sopel-profile1.cfg`, `sopel-profile2.cfg` and `sopel-profile3.cfg` files must be stored in the configuration directory. + +sopel- is mandatory and can be changed with the `sopel_prefix` variable in `/etc/rc.conf` as another FreeBSD service. The service must be installed in `/usr/local/etc/rc.d`: @@ -15,7 +23,7 @@ cp sopel /usr/local/etc/rc.d chmod +x /usr/local/etc/rc.d/sopel ``` -The default configuration file must be installed in ${sopel_confdir}. For example: +The default configuration file must be installed in the configuration directory as another profile. For example: ```sh cp sopel-default.cfg /usr/local/etc @@ -27,9 +35,13 @@ If you want to run sopel at startup, the variable `sopel_enable` must be set to sysrc sopel_enable="YES" ``` -If you want to change the python version, the variable `sopel_interpreter` (by default `/usr/local/bin/python3.9`) must be changed. +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" +``` -Default values: +You can set any other variable, but by default, the sopel service has many default values: ```sh $ egrep -E '^: \$\{sopel_.+:=.+}' sopel From 5cade451a637190dfba35ce5bbeae7ccc4047f74 Mon Sep 17 00:00:00 2001 From: DtxdF Date: Tue, 26 Jul 2022 14:30:25 -0400 Subject: [PATCH 05/10] Explanation of the tools for configuring the sopel service Co-authored-by: mal --- contrib/FreeBSD/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/FreeBSD/README.md b/contrib/FreeBSD/README.md index 296dbcbfd3..d9e46f1a43 100644 --- a/contrib/FreeBSD/README.md +++ b/contrib/FreeBSD/README.md @@ -4,7 +4,7 @@ This folder contains `sopel` and `sopel-default.cfg` designed to be distributed The -default prefix is mandatory and will be used as a 'profile'. -The profiles may be changed with the variable `sopel_profiles` in `/etc/rc.conf`. For example: +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" From f080117341182d9f55e632942932c1ffe8ab388e Mon Sep 17 00:00:00 2001 From: DtxdF Date: Tue, 26 Jul 2022 14:50:14 -0400 Subject: [PATCH 06/10] Explanation of profile examples Co-authored-by: mal --- contrib/FreeBSD/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/FreeBSD/README.md b/contrib/FreeBSD/README.md index d9e46f1a43..1294bc488b 100644 --- a/contrib/FreeBSD/README.md +++ b/contrib/FreeBSD/README.md @@ -12,7 +12,7 @@ sysrc sopel_profiles="profile1 profile2 profile3" By default, the configuration directory is `/usr/local/etc`. -The `sopel-profile1.cfg`, `sopel-profile2.cfg` and `sopel-profile3.cfg` files must be stored in the configuration directory. +For the above example, the configuration files `sopel-profile1.cfg`, `sopel-profile2.cfg`, and `sopel-profile3.cfg` must be present there. sopel- is mandatory and can be changed with the `sopel_prefix` variable in `/etc/rc.conf` as another FreeBSD service. From 2b67a62acb9177fc5f7d523a58dbd7bad3a8313f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Daniel=20Colmenares=20Oviedo?= Date: Tue, 26 Jul 2022 15:16:42 -0400 Subject: [PATCH 07/10] Remove line intended to packagers The `sopel_prefix` is intended to packagers, not end-users --- contrib/FreeBSD/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/contrib/FreeBSD/README.md b/contrib/FreeBSD/README.md index 1294bc488b..ff7c7801ad 100644 --- a/contrib/FreeBSD/README.md +++ b/contrib/FreeBSD/README.md @@ -14,8 +14,6 @@ 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. -sopel- is mandatory and can be changed with the `sopel_prefix` variable in `/etc/rc.conf` as another FreeBSD service. - The service must be installed in `/usr/local/etc/rc.d`: ```sh From c56b7c08f6446b3a9fb34782a5c74e4ae7a5b6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Daniel=20Colmenares=20Oviedo?= Date: Tue, 26 Jul 2022 15:32:59 -0400 Subject: [PATCH 08/10] The sopel service file has been renamed with the extension .sh to be explicit about the scripting language used. --- contrib/FreeBSD/README.md | 2 +- contrib/FreeBSD/{sopel => sopel.sh} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename contrib/FreeBSD/{sopel => sopel.sh} (100%) diff --git a/contrib/FreeBSD/README.md b/contrib/FreeBSD/README.md index ff7c7801ad..7c5853e39e 100644 --- a/contrib/FreeBSD/README.md +++ b/contrib/FreeBSD/README.md @@ -17,7 +17,7 @@ For the above example, the configuration files `sopel-profile1.cfg`, `sopel-prof The service must be installed in `/usr/local/etc/rc.d`: ```sh -cp sopel /usr/local/etc/rc.d +cp sopel.sh /usr/local/etc/rc.d/sopel chmod +x /usr/local/etc/rc.d/sopel ``` diff --git a/contrib/FreeBSD/sopel b/contrib/FreeBSD/sopel.sh similarity index 100% rename from contrib/FreeBSD/sopel rename to contrib/FreeBSD/sopel.sh From 91af425dd52ec3620fb4baa203081db9ed70a6ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Daniel=20Colmenares=20Oviedo?= Date: Tue, 26 Jul 2022 15:40:43 -0400 Subject: [PATCH 09/10] Explanation about the `service sopel configure` --- contrib/FreeBSD/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contrib/FreeBSD/README.md b/contrib/FreeBSD/README.md index 7c5853e39e..e065624e4d 100644 --- a/contrib/FreeBSD/README.md +++ b/contrib/FreeBSD/README.md @@ -33,6 +33,12 @@ If you want to run sopel at startup, the variable `sopel_enable` must be set to sysrc sopel_enable="YES" ``` +Now, you can run the service with the `service(8)` command, but sopel needs to be configured first. You can configure it with `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 From 5dad2dec6073828ebbed6bca994f94300edb9cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Daniel=20Colmenares=20Oviedo?= Date: Wed, 27 Jul 2022 15:16:01 -0400 Subject: [PATCH 10/10] Add instructions for pre-installation of sopel service --- contrib/FreeBSD/README.md | 22 +++++++++++++++++++++- contrib/FreeBSD/sopel-default.cfg | 13 +------------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/contrib/FreeBSD/README.md b/contrib/FreeBSD/README.md index e065624e4d..fb03830687 100644 --- a/contrib/FreeBSD/README.md +++ b/contrib/FreeBSD/README.md @@ -27,13 +27,33 @@ The default configuration file must be installed in the configuration directory 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 sopel needs to be configured first. You can configure it with `service sopel configure`. When sopel is configured, it can be started: +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 diff --git a/contrib/FreeBSD/sopel-default.cfg b/contrib/FreeBSD/sopel-default.cfg index 0da5cc5487..60070a8a86 100644 --- a/contrib/FreeBSD/sopel-default.cfg +++ b/contrib/FreeBSD/sopel-default.cfg @@ -1,18 +1,7 @@ # -# IMPORTANT NOTES! +# IMPORTANT NOTE! # You must delete the not_configured line in order for the bot to work, # otherwise it will refuse to start. -# -# You must create homedir. Sopel should create the others directories: -# mkdir -p $homedir -# The service file has a variable called 'sopel_user'. This user name -# must exist. After creating the user, the owner of the logdir, -# pid_dir and homedir directories must be changed. By default, -# the value is 'sopel': -# chown sopel:sopel $logdir -# chown sopel:sopel $pid_dir -# chown sopel:sopel $homedir -# [core] nick=sopel not_configured=True