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/