ports/155533: [PATCH] update add profiles support to init script for databases/memcached

Steve Wills swills at FreeBSD.org
Sun Mar 13 16:20:10 UTC 2011


>Number:         155533
>Category:       ports
>Synopsis:       [PATCH] update add profiles support to init 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:   Sun Mar 13 16:20:09 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Steve Wills
>Release:        
>Organization:
>Environment:
>Description:
The init script for databases/memcached doesn't allow you to run multiple copies, and if multiple copies are running on the system, it kills them when you restart, even if some of them were started by users. The attach patch changes this so that the init script supports "profiles" for running multiple copies, much the same way the apache init script does. Also, it adds pid file support so that it doesn't kill things that don't belong to it. You can of course still use it without using profiles too, but the pid file support is still there. Had to create a directory to store the pid files in since the nobody user doesn't have write permission to /var/run.
>How-To-Repeat:

>Fix:
See attached.

Patch attached with submission follows:

Index: Makefile
===================================================================
RCS file: /home/ncvs/ports/databases/memcached/Makefile,v
retrieving revision 1.47
diff -u -r1.47 Makefile
--- Makefile	2 Mar 2011 04:08:13 -0000	1.47
+++ Makefile	13 Mar 2011 16:07:36 -0000
@@ -32,7 +32,7 @@
 PLIST_FILES=	bin/memcached \
 		bin/memcached-tool \
 		include/memcached/protocol_binary.h
-PLIST_DIRS=	include/memcached
+PLIST_DIRS=	include/memcached /var/run/memcached
 
 PORTDOCS=	protocol.txt threads.txt readme.txt
 
@@ -67,6 +67,8 @@
 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/ncvs/ports/databases/memcached/files/memcached.in,v
retrieving revision 1.4
diff -u -r1.4 memcached.in
--- files/memcached.in	27 Mar 2010 00:12:46 -0000	1.4
+++ files/memcached.in	13 Mar 2011 16:04:07 -0000
@@ -13,6 +13,8 @@
 #				Default is empty "".
 # memcached_user (user):	Set user to run memcached.
 #				Default is "nobody".
+# memcached_profiles (str):     Set to "" by default.
+#                               Define your profiles here.
 #
 
 . /etc/rc.subr
@@ -20,13 +22,61 @@
 name="memcached"
 rcvar=${name}_enable
 
+_pidprefix="/var/run/memcached/memcached"
+pidfile="${_pidprefix}.pid"
+
 load_rc_config ${name}
 
+if [ -n "$2" ]; then
+	profile="$2"
+	if [ "x${memcached_profiles}" != "x" ]; then
+		pidfile="${_pidprefix}.${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
+		for profile in ${memcached_profiles}; do
+			eval _enable="\${memcached_${profile}_enable}"
+			case "x${_enable:-${memcached_enable}}" in
+			x|x[Nn][Oo]|x[Nn][Oo][Nn][Ee])
+				continue
+				;;
+			x[Yy][Ee][Ss])
+				;;
+			*)
+				if test -z "$_enable"; then
+					_var=memcached_enable
+				else
+					_var=memcached_"${profile}"_enable
+				fi
+				echo "Bad value" \
+				    "'${_enable:-${memcached_enable}}'" \
+				    "for ${_var}. " \
+				    "Profile ${profile} skipped."
+				continue
+				;;
+			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
+				success="${profile} ${success:-}"
+			fi
+		done
+		exit 0
+	fi
+fi
+
 : ${memcached_enable="NO"}
 : ${memcached_user="nobody"}
 
 command=%%PREFIX%%/bin/memcached
-command_args="-d -u ${memcached_user}"
+command_args="-d -u ${memcached_user} -P ${pidfile} "
 
 unset memcached_user
 


>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list