Last active
September 30, 2016 10:27
-
-
Save KakersUK/222bfeeac325f88b067f8341d4293528 to your computer and use it in GitHub Desktop.
/etc/init.d/memcached - Memcached multi-bin init.d script for CentOS 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# | |
# chkconfig: - 55 45 | |
# description: The memcached-multi daemon is a network memory cache service. | |
# processname: memcached-multi | |
# config: /etc/sysconfig/memcached | |
# pidfile: /var/run/memcached/memcached.*.pid | |
# Standard LSB functions | |
#. /lib/lsb/init-functions | |
# Source function library. | |
. /etc/init.d/functions | |
PORT=11211 | |
UDP=0 | |
SOCKET=/tmp/memcached.socket | |
VAR=0 | |
USER=memcached | |
MAXCONN=300 | |
CACHESIZE=64 | |
OPTIONS="" | |
if [ -f /etc/sysconfig/memcached ];then | |
. /etc/sysconfig/memcached | |
fi | |
# Check that networking is up. | |
. /etc/sysconfig/network | |
if [ "$NETWORKING" = "no" ] | |
then | |
exit 0 | |
fi | |
RETVAL=0 | |
prog="memcached" | |
start_instance() { | |
echo -n $"Starting $prog ($1): " | |
daemon --pidfile /var/run/memcached/memcached.$1.pid memcached -d -p $2 -u $USER -m $3 -c $MAXCONN -P /var/run/memcached/memcached.$1.pid $OPTIONS | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached.$1 | |
} | |
stop_instance() { | |
echo -n $"Stopping $prog ($1): " | |
killproc -p /var/run/memcached/memcached.$1.pid /usr/bin/memcached | |
RETVAL=$? | |
echo | |
if [ $RETVAL -eq 0 ] ; then | |
rm -f /var/lock/subsys/memcached.$1 | |
rm -f /var/run/memcached.$1.pid | |
fi | |
} | |
start() { | |
# insure that /var/run/memcached has proper permissions | |
if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then | |
chown $USER /var/run/memcached | |
fi | |
start_instance default $PORT $CACHESIZE; | |
start_instance example.com 11212 $CACHESIZE; | |
} | |
stop () { | |
pids=($(cd /var/run/memcached && /bin/ls *)) | |
for pid in "${pids[@]}" | |
do | |
name=$(echo "$pid" | sed -e "s/memcached.//" | sed -e "s/.pid//") | |
stop_instance "$name"; | |
done | |
} | |
restart () { | |
stop | |
start | |
} | |
# See how we were called. | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status memcached | |
;; | |
restart|reload|force-reload) | |
restart | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}" | |
exit 1 | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stop() looks through pids to remove renamed or removed bins. This will also clean up bins left after a crash or kill all. Good for dynamic deployments such as puppet when using templates.