git: 42b2996954c7 - main - dns/knot-resolver: fixing rc scripts krescachegc and kresd

From: Fernando Apesteguía <fernape_at_FreeBSD.org>
Date: Thu, 08 Aug 2024 14:36:23 UTC
The branch main has been updated by fernape:

URL: https://cgit.FreeBSD.org/ports/commit/?id=42b2996954c75b2fdcce7e306dc47a3bbaf551c2

commit 42b2996954c75b2fdcce7e306dc47a3bbaf551c2
Author:     Leo Vandewoestijne <freebsd@dns.company>
AuthorDate: 2024-08-07 15:37:28 +0000
Commit:     Fernando Apesteguía <fernape@FreeBSD.org>
CommitDate: 2024-08-08 14:36:09 +0000

    dns/knot-resolver: fixing rc scripts krescachegc and kresd
    
     * kresd.i lacked activation of defined status_cmd="${name}_status"
    
     * dns/knot-resolver/files/krescachegc.in needed full clean-up:
    
            * daemon didn't start due to missing '-c <resolver_cache>'
            * missing 'start', 'stop' and 'status' functionality added
    
    PR:             277540
    Reported by:    trashcan@ellael.org
---
 dns/knot-resolver/Makefile             |  3 +-
 dns/knot-resolver/distinfo             |  6 ++--
 dns/knot-resolver/files/krescachegc.in | 52 ++++++++++++++++++++++++++++++----
 dns/knot-resolver/files/kresd.in       | 52 ++++++++++++++++++----------------
 dns/knot-resolver/pkg-plist            |  2 +-
 5 files changed, 79 insertions(+), 36 deletions(-)

diff --git a/dns/knot-resolver/Makefile b/dns/knot-resolver/Makefile
index 9bb5b7bf6fb0..9de847ea9946 100644
--- a/dns/knot-resolver/Makefile
+++ b/dns/knot-resolver/Makefile
@@ -1,6 +1,5 @@
 PORTNAME=	knot-resolver
-DISTVERSION=	5.7.2
-PORTREVISION=	1
+DISTVERSION=	5.7.3
 CATEGORIES=	dns
 MASTER_SITES=	https://secure.nic.cz/files/knot-resolver/ \
 		https://dns.company/downloads/knot-resolver/
diff --git a/dns/knot-resolver/distinfo b/dns/knot-resolver/distinfo
index b06f3c43b9c4..837708ed2a7d 100644
--- a/dns/knot-resolver/distinfo
+++ b/dns/knot-resolver/distinfo
@@ -1,3 +1,3 @@
-TIMESTAMP = 1713104201
-SHA256 (knot-resolver-5.7.2.tar.xz) = 5f6a227390fcd4c2d0a8028a652b55a9d863ec7be01298fe038df1d273fb9a0f
-SIZE (knot-resolver-5.7.2.tar.xz) = 1928336
+TIMESTAMP = 1722850725
+SHA256 (knot-resolver-5.7.3.tar.xz) = efc6e45ffc5efd98921ea5cd3fece166a1a5ce9eaa12d41b46268964353dbedb
+SIZE (knot-resolver-5.7.3.tar.xz) = 1930732
diff --git a/dns/knot-resolver/files/krescachegc.in b/dns/knot-resolver/files/krescachegc.in
index 40334bea0bdc..8b04fc0686e4 100644
--- a/dns/knot-resolver/files/krescachegc.in
+++ b/dns/knot-resolver/files/krescachegc.in
@@ -18,16 +18,58 @@ name=krescachegc
 rcvar=krescachegc_enable
 
 load_rc_config ${name}
+load_rc_config_var kresd rundir
+load_rc_config_var kresd user
 
-# set defaults
-krescachegc_enable=${krescachegc_enable:-"NO"}
+: ${krescachegc_enable:="NO"}
 : ${krescachegc_svcj_options:="net_basic"}
-krescachegc_millis=${krescachegc_millis:-"1000"}
+: ${krescachegc_millis:="1000"}
+: ${kresd_rundir:="/var/run/kresd"}
+: ${kresd_user:="%%USERS%%"}
 
-pidfile="%%RUNDIR%%/${name}.pid"
 procname="%%PREFIX%%/sbin/kres-cache-gc"
 
+start_cmd="${name}_start"
+stop_cmd="${name}_stop"
+status_cmd="${name}_status"
+
 command=/usr/sbin/daemon
-command_args="-c -f -S -r -P ${pidfile} -T ${name} -u %%USERS%% -- ${procname} -d ${krescachegc_millis}"
+command_args="-c -f -r -S -u ${kresd_user} -T ${name} -- ${procname} -c ${kresd_rundir} -d ${krescachegc_millis}"
+
+krescachegc_start() {
+	/bin/pgrep -f ${procname} > /dev/null && status="$?" || status="$?"
+	if [ "${status}" -eq 0 ]; then
+		echo "${name} already seems to be running."
+	else
+		echo "starting ${name}..." && \
+		${command} ${command_args}
+		echo -e "\e[1A\e[K${name} started."
+	fi
+	}
+
+krescachegc_status() {
+	/bin/pgrep -f ${procname} > /dev/null && status="$?" || status="$?"
+	if [ "${status}" -eq 0 ]; then
+		echo "${name} is running:"
+		echo
+		/bin/ps -p $(/bin/pgrep -f ${procname})
+	else
+		echo "${name} is not running"
+	fi
+	return ${status}
+	}
+
+krescachegc_stop() {
+	/bin/pgrep -f ${procname} > /dev/null && status="$?" || status="$?"
+	if [ "${status}" -eq 0 ]; then
+		echo "stopping ${name}..." && \
+		/bin/pkill -TERM -f ${procname}
+		echo -e "\e[1A\e[K${name} stopped."
+
+	else
+		echo "${name} is not running"
+	fi
+	return ${status}
+	}
 
 run_rc_command "$1"
diff --git a/dns/knot-resolver/files/kresd.in b/dns/knot-resolver/files/kresd.in
index 0ddd5d332466..c322d5e85470 100644
--- a/dns/knot-resolver/files/kresd.in
+++ b/dns/knot-resolver/files/kresd.in
@@ -20,57 +20,59 @@ rcvar=kresd_enable
 
 load_rc_config ${name}
 
-# set defaults
-kresd_enable=${kresd_enable:-"NO"}
+: ${kresd_enable:="NO"}
 : ${kresd_svcj_options:="net_basic"}
-kresd_config=${kresd_config:-"%%ETCDIR%%/${name}.conf"}
-kresd_user="%%USERS%%"
-kresd_group="%%GROUPS%%"
-kresd_rundir="/var/run/${name}"
+: ${kresd_config:="%%ETCDIR%%/${name}.conf"}
+: ${kresd_user:="%%USERS%%"}
+: ${kresd_group:="%%GROUPS%%"}
+: ${kresd_rundir:="%%RUNDIR%%"}
 
-pidfile="${kresd_rundir}/${name}.pid"
 procname="%%PREFIX%%/sbin/${name}"
 required_files="${kresd_config}"
 
 start_cmd="${name}_start"
+status_cmd="${name}_status"
 stop_cmd="${name}_stop"
 
 command="/usr/sbin/daemon"
-command_args="-c -f -S -r -P ${pidfile} -T ${name} -- ${procname} -c ${kresd_config} -n -q ${kresd_rundir}"
+command_args="-c -f -r -S -T ${name} -- ${procname} -c ${kresd_config} -n -q ${kresd_rundir}"
 
 kresd_start() {
 	if [ ! -d /var/run/${name} ]; then
 		install -d -o ${kresd_user} -g ${kresd_group} -m 700 ${kresd_rundir}
 	fi
-	if [ ! -f "${pidfile}" ]; then
+	/bin/pgrep -f ${procname} > /dev/null && status="$?" || status="$?"
+	if [ "${status}" -eq 0 ]; then
+		echo "${name} already seems to be running."
+	else
 		echo "starting ${name}..." && \
 		${command} ${command_args}
 		echo -e "\e[1A\e[K${name} started."
+	fi
+	}
+
+kresd_status() {
+	/bin/pgrep -f ${procname} > /dev/null && status="$?" || status="$?"
+	if [ "${status}" -eq 0 ]; then
+		echo "${name} is running:"
+		echo
+		/bin/ps -p $(/bin/pgrep -f ${procname})
 	else
-		echo "${name} already seems to be running."
+		echo "${name} is not running"
 	fi
+	return ${status}
 	}
 
 kresd_stop() {
-	if [ -f "${pidfile}" ]; then
+	/bin/pgrep -f ${procname} > /dev/null && status="$?" || status="$?"
+	if [ "${status}" -eq 0 ]; then
 		echo "stopping ${name}..." && \
-		for pid in `ps waux | grep ${procname} | grep daemon | awk '{print $2}'`; do \
-			kill -TERM $pid
-		done
+		/bin/pkill -TERM -f ${procname}
 		echo -e "\e[1A\e[K${name} stopped."
 	else
-		echo "${name} seems to be not running."
+		echo "${name} is not running"
 	fi
+	return ${status}
 	}
 
-kresd_status() {
-    if [ -e "${pidfile}" ]; then
-        echo "${name} is running on pid $(cat $pidfile)."
-        return 1
-    else
-        echo "${name} is not running."
-        return 0
-    fi
-}
-
 run_rc_command "$1"
diff --git a/dns/knot-resolver/pkg-plist b/dns/knot-resolver/pkg-plist
index 769c84a35f19..7ee88fee52b1 100644
--- a/dns/knot-resolver/pkg-plist
+++ b/dns/knot-resolver/pkg-plist
@@ -96,4 +96,4 @@ sbin/kres-cache-gc
 sbin/kresc
 sbin/kresd
 @dir(%%USERS%%,%%GROUPS%%,0755) %%ETCDIR%%
-@dir(%%USERS%%,%%GROUPS%%,0660) %%RUNDIR%%
+@dir(%%USERS%%,%%GROUPS%%,0700) %%RUNDIR%%