ports/databases/memcached/files/memcached.in
Doug Barton 83eb2c3700 In the rc.d scripts, change assignments to rcvar to use the
literal name_enable wherever possible, and ${name}_enable
when it's not, to prepare for the demise of set_rcvar().

In cases where I had to hand-edit unusual instances also
modify formatting slightly to be more uniform (and in
some cases, correct). This includes adding some $FreeBSD$
tags, and most importantly moving rcvar= to right after
name= so it's clear that one is derived from the other.
2012-01-14 08:57:23 +00:00

99 lines
2.3 KiB
Bash

#!/bin/sh
# $FreeBSD$
#
# PROVIDE: memcached
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to run memcached:
#
# memcached_enable (bool): Set it to "YES" to enable memcached.
# Default is "NO".
# memcached_flags (flags): Set extra flags here. More options in memcached(1)
# 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
name="memcached"
rcvar=memcached_enable
_piddir="/var/run/memcached"
pidfile="${_piddir}/memcached.pid"
load_rc_config ${name}
if [ -n "$2" ]; then
profile="$2"
if [ -n "${memcached_profiles}" ]; then
pidfile="${_piddir}/memcached.${profile}.pid"
eval memcached_enable="\${memcached_${profile}_enable:-${memcached_enable}}"
eval memcached_flags="\${memcached_${profile}_flags:-${memcached_flags}}"
else
echo "%%PREFIX%%/etc/rc.d/memcached%%RC_SUBR_SUFFIX%%: extra argument ignored"
fi
else
if [ -n "${memcached_profiles}" -a -n "$1" ]; then
for profile in ${memcached_profiles}; do
eval _enable="\${memcached_${profile}_enable}"
case "${_enable:-${memcached_enable}}" in
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
continue
;;
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
;;
*)
if test -z "$_enable"; then
_var=memcached_enable
else
_var=memcached_"${profile}"_enable
fi
warn "Bad value" \
"'${_enable:-${memcached_enable}}'" \
"for ${_var}. " \
"Profile ${profile} skipped."
continue
;;
esac
echo "===> memcached profile: ${profile}"
if %%PREFIX%%/etc/rc.d/memcached%%RC_SUBR_SUFFIX%% $1 ${profile} ; then
success="${profile} ${success:-}"
else
failed="${profile} (${retcode}) ${failed:-}"
fi
done
exit 0
fi
fi
memcached_poststop()
{
if [ -n "${profile}" ]; then
[ -e "$pidfile" ] && unlink $pidfile
else
local file
for file in ${_piddir}/* ; do
case "$file" in
*\*)
continue ;;
esac
unlink $file
done
fi
}
: ${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"