Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save developer-rakeshpaul/0f85bf25940970e75f3e1b6bebac3231 to your computer and use it in GitHub Desktop.

Select an option

Save developer-rakeshpaul/0f85bf25940970e75f3e1b6bebac3231 to your computer and use it in GitHub Desktop.

Revisions

  1. @tinogomes tinogomes revised this gist Jun 21, 2010. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions start_stop_memcached_script.sh
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    #!/bin/bash
    #
    BASE=/tmp
    PID=/tmp/app.pid
    LOG=/tmp/app.log
    ERROR=/tmp/app-error.log
    PID=$BASE/app.pid
    LOG=$BASE/app.log
    ERROR=$BASE/app-error.log

    PORT=11200
    LISTEN_IP = '0.0.0.0'
    PORT=11211
    LISTEN_IP='0.0.0.0'
    MEM_SIZE=4
    CMD='memcached'
    COMMAND='$CMD -p $PORT -l $LISTEN_IP -d -m $MEM_SIZE -v -p $PID'
    COMMAND="$CMD -p $PORT -l $LISTEN_IP -m $MEM_SIZE -v"

    USR=user

  2. @tinogomes tinogomes renamed this gist Jun 21, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @tinogomes tinogomes created this gist Jun 21, 2010.
    110 changes: 110 additions & 0 deletions start_stop_script.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,110 @@
    #!/bin/bash
    #
    BASE=/tmp
    PID=/tmp/app.pid
    LOG=/tmp/app.log
    ERROR=/tmp/app-error.log

    PORT=11200
    LISTEN_IP = '0.0.0.0'
    MEM_SIZE=4
    CMD='memcached'
    COMMAND='$CMD -p $PORT -l $LISTEN_IP -d -m $MEM_SIZE -v -p $PID'

    USR=user

    status() {
    echo
    echo "==== Status"

    if [ -f $PID ]
    then
    echo
    echo "Pid file: $( cat $PID ) [$PID]"
    echo
    ps -ef | grep -v grep | grep $( cat $PID )
    else
    echo
    echo "No Pid file"
    fi
    }

    start() {
    if [ -f $PID ]
    then
    echo
    echo "Already started. PID: [$( cat $PID )]"
    else
    echo "==== Start"
    touch $PID
    if nohup $COMMAND >>$LOG 2>&1 &
    then echo $! >$PID
    echo "Done."
    echo "$(date '+%Y-%m-%d %X'): START" >>$LOG
    else echo "Error... "
    /bin/rm $PID
    fi
    fi
    }

    kill_cmd() {
    SIGNAL=""; MSG="Killing "
    while true
    do
    LIST=`ps -ef | grep -v grep | grep $CMD | grep -w $USR | awk '{print $2}'`
    if [ "$LIST" ]
    then
    echo; echo "$MSG $LIST" ; echo
    echo $LIST | xargs kill $SIGNAL
    sleep 2
    SIGNAL="-9" ; MSG="Killing $SIGNAL"
    if [ -f $PID ]
    then
    /bin/rm $PID
    fi
    else
    echo; echo "All killed..." ; echo
    break
    fi
    done
    }

    stop() {
    echo "==== Stop"

    if [ -f $PID ]
    then
    if kill $( cat $PID )
    then echo "Done."
    echo "$(date '+%Y-%m-%d %X'): STOP" >>$LOG
    fi
    /bin/rm $PID
    kill_cmd
    else
    echo "No pid file. Already stopped?"
    fi
    }

    case "$1" in
    'start')
    start
    ;;
    'stop')
    stop
    ;;
    'restart')
    stop ; echo "Sleeping..."; sleep 1 ;
    start
    ;;
    'status')
    status
    ;;
    *)
    echo
    echo "Usage: $0 { start | stop | restart | status }"
    echo
    exit 1
    ;;
    esac

    exit 0