Skip to content

Instantly share code, notes, and snippets.

@pawitp
Created November 28, 2015 06:12
Show Gist options
  • Save pawitp/0b0c9023b0dfc86db5db to your computer and use it in GitHub Desktop.
Save pawitp/0b0c9023b0dfc86db5db to your computer and use it in GitHub Desktop.

Revisions

  1. pawitp created this gist Nov 28, 2015.
    82 changes: 82 additions & 0 deletions memcached-$USER
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    #! /bin/sh
    #
    # chkconfig: - 55 45
    # description: The memcached daemon is a network memory cache service.
    # processname: memcached
    # pidfile: /var/run/memcached-$USER/memcached.pid

    # Standard LSB functions
    #. /lib/lsb/init-functions

    # Source function library.
    . /etc/init.d/functions

    PORT=11211
    USER=yourusernamegoeshere
    MAXCONN=1024
    CACHESIZE=64
    OPTIONS="-s /home/$USER/memcached.sock"

    # Check that networking is up.
    . /etc/sysconfig/network

    if [ "$NETWORKING" = "no" ]
    then
    exit 0
    fi

    RETVAL=0
    prog="memcached-$USER"

    start () {
    echo -n $"Starting $prog: "
    # insure that /var/run/memcached-$USER has proper permissions
    if [ "`stat -c %U /var/run/memcached-$USER`" != "$USER" ]; then
    chown $USER /var/run/memcached-$USER
    fi

    daemon --pidfile /var/run/memcached-$USER/memcached.pid memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached-$USER/memcached.pid $OPTIONS
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached-$USER
    }
    stop () {
    echo -n $"Stopping $prog: "
    killproc -p /var/run/memcached-$USER/memcached.pid /usr/bin/memcached
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ] ; then
    rm -f /var/lock/subsys/memcached-$USER
    rm -f /var/run/memcached-$USER/memcached.pid
    fi
    }

    restart () {
    stop
    start
    }


    # See how we were called.
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    status)
    status -p /var/run/memcached-$USER/memcached.pid memcached-$USER
    ;;
    restart|reload|force-reload)
    restart
    ;;
    condrestart)
    [ -f /var/lock/subsys/memcached-$USER ] && restart || :
    ;;
    *)
    echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
    exit 1
    esac

    exit $?