Automatic restart script after the memcached process hangs out

Source: Internet
Author: User
Tags memcached

Because the memcached of a Web server dies, it does not open when visiting certain pages of the site. The following script automatically detects the memcached process and automatically restarts the memcached service if it hangs.

Vim memcached_check.sh

#!/bin/sh

#check memcached process and restart if down

Path= $PATH:/opt/env/memcache/bin/memcached

Date= ' date-d ' "Today" + "%y-%m-%d-%h:%m"

#用ps命令查看memcached进程

mm= ' Ps-aux |grep ' memcached ' |grep ' 11211 ' |grep-v ' grep ' |wc-l '

#if语句判断进程是否存在, if not present, output logging and restart the memcached service

If ["$MM" = = "0"]; Then

echo "$DATE The memcached is problem and restart" >>/root/sh/memcached_check.logs

/opt/env/memcache/bin/memcached-t 8-d-M 2048-p 11211-u Nobody

Else

#echo "$DATE The memcached is OK" >>/root/sh/memcached_check.logs

Fi

Add scheduled tasks to be detected every 5 minutes.

*/5 * * * */bin/bash/root/sh/memcached_check.sh

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/web/

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.