Linux下,DIY apache和memcache守护进程
来源:互联网 发布:网络服务器 书籍 编辑:程序博客网 时间:2024/06/05 00:31
端午节,睡梦中,被电话惊醒,web服务器挂了,恼火坏了。登陆服务器一阵忙活,发现apache服务器和memcache服务器非法关闭了。哎,为了睡得安稳,抓紧写个小脚本来监控下appach和memcache吧!很快就有了下面的脚本:
#!/bin/bash -name=`basename $0 .sh`function showHelp(){ echo "Usage: $name" echo " $name test|dev" exit 1}if [ $# -ne 0 -a $# -ne 1 ]; then showHelpfi#正式/测试环境test=0if [ $# -eq 1 ]; then# echo "$1" if [ "$1" = "dev" -o "$1" = "test" ]; then test=1 else showHelp fifi#echo $testwebsrvkey=/bin/httpdwebsrvbin=/etc/init.d/apachectlcachekey=/memcachedcachebin=/usr/local/memcached/bin/memcachedcachepid=/usr/local/memcached/memcached.pidcachedir=/usr/local/memcached#run web serverfunction startweb(){ echo "`date` start websrv..." if [ ! -f $websrvbin ]; then echo "`date` websrv bin [$websrvbin] not exist..." return fi $websrvbin start echo "`date` start websrv complete..."}#run cachefunction startcache(){ echo "`date` start cache..." if [ $test -eq 1 ]; then cachebin=/usr/bin/memcached fi if [ ! -f $cachebin ]; then echo "`date` cache bin [$cachebin] not exist..." return fi if [ ! -d $cachedir ]; then echo "`date` cache dir not exist..." mkdir $cachedir echo "`date` create dir $cachedir" fi if [ $test -eq 0 ]; then $cachebin -d -m 100 -uroot -l 0.0.0.0 -p 11000 -c 512 -P $cachepid else $cachebin -d -m 128 -l 192.168.119.60 -p 12000 -u ossh fi echo "`date` start cache complete..."}cnt=`ps -ef | grep $websrvkey | grep -vc grep`# echo $cntif [ $cnt -le 0 ]; then startwebficnt=`ps -ef | grep $cachekey | grep -vc grep`#echo $cntif [ $cnt -le 0 ]; then startcachefi
把上面的脚本保存为monitorWebSrv.sh,并对该文件赋予可执行权限,进行如下操作:
chmod +x /etc/app/slightphp/public/csevent/bin/crontab/monitorWebSrv.sh
然后加入crontab计划任务,如下:
* * * * * /etc/app/slightphp/public/csevent/bin/crontab/monitorWebSrv.sh >> /tmp/monitorWebSrv.log* * * * * sleep 30; /etc/app/slightphp/public/csevent/bin/crontab/monitorWebSrv.sh >> /tmp/monitorWebSrv.log
为什么加两条呢?为了每隔30秒执行一次!
对于shell和crontab,请参阅以前的blog:shell脚本比较运算符及逻辑运算符小结 、Linux Shell脚本逻辑操作符简介 及Linux crontab命令小结
- Linux下,DIY apache和memcache守护进程
- Linux下守护进程
- Linux下守护进程
- linux 下守护进程
- Linux 下创建守护进程
- Linux下后台守护进程
- Linux下编写守护进程
- Linux下的守护进程
- Linux下的守护进程
- Linux下编写守护进程
- linux下的守护进程
- Linux下的守护进程
- Linux下的守护进程
- Linux下的守护进程
- Linux下的守护进程
- Linux下的守护进程
- linux下的守护进程
- Linux下的守护进程(Python和C版)
- CE BSP开发入门(1)
- android 图像处理滤镜系列
- CE BSP开发入门(2)
- Ubuntu 11.10编译Android 错误
- 解决在SQL server 2000中病毒时遇到的Microsoft SQL-DMO(ODBC SQLState :42000)问题
- Linux下,DIY apache和memcache守护进程
- VC操作注册表函数
- 程序员的7个坏习惯来源: 开源中国社区 发布时间: 2012-06-03 08:38 阅读: 5543 次 原文链接 全屏阅读 [收藏]
- HandlerThread
- android post
- JAVA中事件处理的总结
- 进步又下降。。。
- 三种Cache写入方式原理简介
- Smack 结合 Openfire服务器,建立IM通信,发送聊天消息