Linux, DIY Apache and memcache daemon __linux

Source: Internet
Author: User
Tags logical operators memcached

Dragon Boat Festival, Sleep, was awakened by the phone, the Web server hung up, irritated bad. A busy landing server, found that the Apache server and memcache server illegally shut down. Hey, in order to sleep well, hurry to write a little foot originally monitoring the Appach and Memcache bar. The following script is soon available:


#!/bin/bash-name= ' basename $ sh ' function showHelp () {echo "Usage: $name" echo "$name Test|dev "Exit 1} If [$#-ne 0-a $#-ne 1];" Then showHelp fi #正式/test environment test=0 IF [$#-eq 1]; Then # echo "$" if ["$" = "Dev"-o "$" = "test"]; Then test=1 else showHelp fi fi #echo $test websrvkey=/bin/httpd websrvb In=/etc/init.d/apachectl cachekey=/memcached cachebin=/usr/local/memcached/bin/memcached cachepid=/usr/local/ Memcached/memcached.pid cachedir=/usr/local/memcached #run Web server function Startweb () {echo ' ' date ' start we Bsrv. "If [!-f $websrvbin]; Then echo "' Date ' websrv bin [$websrvbin] not exist ..." return fi $websrvb


In start echo "' Date ' start websrv complete ..."} #run cache function 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 ' CR Eate 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 $cach
Ebin-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 $cnt if [$cnt-le 0]; Then Startweb fi cnt= ' Ps-ef | grep $cachekey | GREP-VC grep ' #echo $cnt if [$cnt-le 0];
 Then StartCache fi


Save the above script as monitorwebsrv.sh and give the file executable permission to do the following:

chmod +x  /etc/app/slightphp/public/csevent/bin/crontab/monitorwebsrv.sh

Then join the Crontab planning task as follows:

* * * * */etc/app/slightphp/public/csevent/bin/crontab/monitorwebsrv.sh >>/tmp/monitorwebsrv.log * * * * * * * * * * *
SLE EP 30; /etc/app/slightphp/public/csevent/bin/crontab/monitorwebsrv.sh >>/tmp/monitorwebsrv.log

Why add two? To be executed every 30 seconds.

For shells and crontab, see previous Blog:shell script comparison operators and logical operator summaries, Introduction to Linux shell scripting logical operators, and a summary of Linux crontab commands





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.