ports/161109: Fix rc.d script for databases/memcached

Doug Barton dougb at FreeBSD.org
Wed Sep 28 21:40:06 UTC 2011


>Number:         161109
>Category:       ports
>Synopsis:       Fix rc.d script for databases/memcached
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 28 21:40:05 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Doug Barton
>Release:        FreeBSD 8.2-STABLE i386
>Organization:
AAAG
>Environment:
	DNA
>Description:
	The rc.d script for memcached has various problems:

	1. Creating /var/run/memcached in the Makefile does nothing for
	   package installs.
	2. Because the service runs as an unprivileged user it must
	   REQUIRE: LOGIN
	3. The rc.d script should create the directory in /var/run, and give
	   it appropriate permissions.
	4. The rc.d script should clean up pidfiles since the software doesn't
	5. Various other shell cleanups.

>How-To-Repeat:
	DNA
>Fix:
	Apply the following patch:

Index: Makefile
===================================================================
RCS file: /home/pcvs/ports/databases/memcached/Makefile,v
retrieving revision 1.52
diff -u -r1.52 Makefile
--- Makefile	23 Sep 2011 22:21:35 -0000	1.52
+++ Makefile	28 Sep 2011 21:09:46 -0000
@@ -7,6 +7,7 @@
 
 PORTNAME=	memcached
 PORTVERSION=	1.4.7
+PORTREVISION=	1
 CATEGORIES=	databases
 MASTER_SITES=	${MASTER_SITE_GOOGLE_CODE} \
 		${MASTER_SITE_GENTOO}
@@ -31,7 +32,7 @@
 PLIST_FILES=	bin/memcached \
 		bin/memcached-tool \
 		include/memcached/protocol_binary.h
-PLIST_DIRS=	include/memcached /var/run/memcached
+PLIST_DIRS=	include/memcached
 
 PORTDOCS=	protocol.txt readme.txt
 
@@ -65,8 +66,6 @@
 post-install:
 	${INSTALL_SCRIPT} ${WRKSRC}/scripts/memcached-tool ${PREFIX}/bin
 	${INSTALL_MAN} ${WRKSRC}/doc/${MAN1} ${MAN1PREFIX}/man/man1
-	@${MKDIR} -p /var/run/memcached
-	@${CHOWN} nobody:nobody /var/run/memcached
 .if !defined(NOPORTDOCS)
 	@${ECHO_MSG} "===>   Installing documentation for ${PKGNAME}"
 	@${MKDIR} ${DOCSDIR}
Index: files/memcached.in
===================================================================
RCS file: /home/pcvs/ports/databases/memcached/files/memcached.in,v
retrieving revision 1.6
diff -u -r1.6 memcached.in
--- files/memcached.in	14 Aug 2011 00:44:33 -0000	1.6
+++ files/memcached.in	28 Sep 2011 21:09:46 -0000
@@ -1,9 +1,9 @@
 #!/bin/sh
-#
+
 # $FreeBSD: ports/databases/memcached/files/memcached.in,v 1.6 2011/08/14 00:44:33 swills Exp $
 #
 # PROVIDE: memcached
-# REQUIRE: DAEMON
+# REQUIRE: LOGIN
 # KEYWORD: shutdown
 #
 # Add the following lines to /etc/rc.conf to run memcached:
@@ -16,36 +16,35 @@
 #				Default is "nobody".
 # memcached_profiles (str):     Set to "" by default.
 #                               Define your profiles here.
-#
 
 . /etc/rc.subr
 
 name="memcached"
 rcvar=${name}_enable
 
-_pidprefix="/var/run/memcached/memcached"
-pidfile="${_pidprefix}.pid"
+_piddir="/var/run/memcached"
+pidfile="${_piddir}/memcached.pid"
 
 load_rc_config ${name}
 
 if [ -n "$2" ]; then
 	profile="$2"
 	if [ "x${memcached_profiles}" != "x" ]; then
-		pidfile="${_pidprefix}.${profile}.pid"
+		pidfile="${_piddir}/memcached.${profile}.pid"
 		eval memcached_enable="\${memcached_${profile}_enable:-${memcached_enable}}"
 		eval memcached_flags="\${memcached_${profile}_flags:-${memcached_flags}}"
 	else
 		echo "$0: extra argument ignored"
 	fi
 else
-	if [ "x${memcached_profiles}" != "x" -a "x$1" != "x" ]; then
+	if [ -n "${memcached_profiles}" -a -n "$1" ]; then
 		for profile in ${memcached_profiles}; do
 			eval _enable="\${memcached_${profile}_enable}"
-			case "x${_enable:-${memcached_enable}}" in
-			x[Nn][Oo]|x[Ff][Aa][Ll][Ss][Ee]|x[Oo][Ff][Ff]|x0)
+			case "${_enable:-${memcached_enable}}" in
+			[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
 				continue
 				;;
-			x[Yy][Ee][Ss]|x[Tt][Rr][Uu][Ee]|x[Oo][Nn]|x1)
+			[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
 				;;
 			*)
 				if test -z "$_enable"; then
@@ -53,7 +52,7 @@
 				else
 					_var=memcached_"${profile}"_enable
 				fi
-				echo "Bad value" \
+				warn "Bad value" \
 				    "'${_enable:-${memcached_enable}}'" \
 				    "for ${_var}. " \
 				    "Profile ${profile} skipped."
@@ -61,22 +60,33 @@
 				;;
 			esac
 			echo "===> memcached profile: ${profile}"
-			/usr/local/etc/rc.d/memcached $1 ${profile}
-			retcode="$?"
-			if [ "0${retcode}" -ne 0 ]; then
-				failed="${profile} (${retcode}) ${failed:-}"
-			else
+			if $0 $1 ${profile} ; then
 				success="${profile} ${success:-}"
+			else
+				failed="${profile} (${retcode}) ${failed:-}"
 			fi
 		done
 		exit 0
 	fi
 fi
 
+memcached_poststop()
+{
+	local file
+
+	for file in ${_piddir}/* ; do
+		case "$file" in *\*) continue ;; esac
+		unlink $file
+	done
+}
+
 : ${memcached_enable="NO"}
 : ${memcached_user="nobody"}
 
 command=%%PREFIX%%/bin/memcached
 command_args="-d -u ${memcached_user} -P ${pidfile} "
 
+start_precmd="install -d -o $memcached_user -g $memcached_user -m 755 $_piddir"
+stop_postcmd="${name}_poststop"
+
 run_rc_command "$1"
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list