Start and monitor of SH memcached process

Source: Internet
Author: User
Tags memcached printf sleep

1.memcached_inc.sh

Sets the path, port, and other messages.

#!/bin/sh  
     
#config include  
     
host=$ (hostname)  
site= "MySite"  
port=11211  
     
memcached_pid_file= "/ Tmp/memcached.pid "  
memcached_daemon_pid_file="/tmp/memcached_daemon.pid "  
     
memcached=" memcached-d-M 64-p $ Port-u memcache-l 127.0.0.1-p $MEMCACHED _pid_file "memcached_daemon_file=" memcached_daemon.sh  
     
File= "${root}/memcached_${site}_${host}_${port}.log"

Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/

2.gm_memcached.sh

Control memcached start, stop, reboot.

#!/bin/sh #memcached start and stop #$1 action root=$ (CD "$ (dirname" $) "; pwd). ${root}/memcached_inc.sh Start () {if [-F "$MEMCACHED _pid_file"] && [S "$MEMCACHED _p Id_file "]; Then printf "memcached already running\n" Else printf "starting memcached\n" $MEMCACHE D Sleep 2 pid=$ (cat $MEMCACHED _pid_file) printf ' MEMCACHED is started PID: $PID \ n "printf" Starting memcached daemon\n "${root}/${memcached_daemon_file} & Daemon_p  
        id=$!  
    Echo ${daemon_pid} > ${memcached_daemon_pid_file} printf "MEMCACHED DAEMON is started pid:${daemon_pid}\n" fi} stop () {if [F] $MEMCACHED _daemon_pid_file] && [s] $MEMCACHED _dae Mon_pid_file "];  
      Then daemon_pid=$ (cat $MEMCACHED _daemon_pid_file) rm-f ${memcached_daemon_pid_file}  if [!-Z ${daemon_pid}];  
        Then kill-9 ${daemon_pid} fi printf "memcached DAEMON is stopped\n" else printf "No memcached daemon running\n" fi sleep 1 if [-F "$MEMCACHED _pid_file"] &&am P [-S "$MEMCACHED _pid_file"]; Then pid=$ (cat $MEMCACHED _pid_file) rm-f ${memcached_pid_file} if [!-Z ${pid}]; Then kill-9 ${pid} fi printf "memcached is stopped\n" else printf "no m  
     
    emcached running\n "fi} Case", "in Start" start;;  
     
    stop) stop;;  
     
    Restart) Stop sleep 3 start;; *) printf "usage:$0 {start|stop|restart}\n" Exit 1 ESAC Exit 0

3.memcached_daemon.sh

Monitor memcached processes, such as failure of processes to start automatically.

#!/bin/sh  
     
#memcached Daemon  
     
root=$ (cd "$ (dirname" $) "pwd)  
     
. ${root}/memcached_inc.sh while  
     
     
:  
do  
    if [f "$MEMCACHED _pid_file"] && [S "$MEMCACHED _pid_file]; then  
        pid=$ (cat $MEMCACHED _pid_fi LE)  
    Else  
        pid= "" "  
    fi  
        
    If [-Z" $PID "] | | [-Z $ (ps Aux|awk ' {print $} ' | grep ' ^ $PID $ ")]; Then  
        $MEMCACHED sleep  
        1  
        printf "[$ (Date +%y-%m-%d '%h:%m:%s)] ${site} ${host} MEMCACHED ${port} is restarted\n ">> $ERROR _log_file  
        echo" Subject: ${site} ${host} memcached ${port} is restarted $ (date +%y-%m-%d '%h:%m:%s ' | SendMail me@gmail.com  
    fi  
     
    5 done  
     
exit 0

How to use:

./gm_memcached.sh start   #启动memcached  
./gm_memcached.sh Stop    #停止memcached  
./gm_memcached.sh Restart #重启memcached

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.