Memcached进程挂掉自动重启脚本

简介:

  由于一台WEB服务器的Memcached死掉而导致在访问网站的某些页面时候打不开,下面脚本会自动检测Memcached的进程,如果挂掉则自动重启Memcached服务。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat  /root/sh/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语句判断进程是否存在,如果不存在,输出日志记录并重启memcached服务
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
#添加计划任务,每5分钟检测一次。
* /5  * * * *  /bin/bash     /root/sh/memcached_check .sh









本文转自 sfzhang 51CTO博客,原文链接:http://blog.51cto.com/sfzhang88/874388,如需转载请自行联系原作者

目录
相关文章
|
4天前
|
监控 Shell
在Shell中自动重启进程
在Shell中自动重启进程
167 1
|
4天前
|
Shell Linux 开发工具
linux shell脚本利用 kill -0 检查进程是否存在
linux shell脚本利用 kill -0 检查进程是否存在
62 1
|
4天前
|
Java Shell
通过端口杀掉进程的脚本
通过端口杀掉进程的脚本
8 0
|
4天前
|
监控 Java Linux
linux下监控java进程 实现自动重启服务
linux下监控java进程 实现自动重启服务
|
4天前
|
监控 Python Windows
使用python脚本来监控进程
使用python脚本来监控进程
|
4天前
|
Unix Shell Linux
shell脚本中创建子进程
shell脚本中创建子进程
159 2
|
4天前
|
Shell Perl
在Shell脚本中,检查一个进程是否正在运行
在Shell脚本中,检查一个进程是否正在运行
323 1
|
4天前
|
监控 Shell
Shell脚本进程监控
Shell脚本进程监控
32 2
|
4天前
|
存储 Linux Shell
Linux:进程等待 & 进程替换
Linux:进程等待 & 进程替换
30 9
|
4天前
|
存储 Linux C语言
Linux:进程创建 & 进程终止
Linux:进程创建 & 进程终止
27 6

相关实验场景

更多