几个启动和检测脚本 防止自己忘记

几个启动和检测脚本 防止自己忘记


nginx 启动脚本:

#!/bin/sh
# Startup script forthe Nginx
# chkconfig: - 8863
# description: Nginx isa free,open-source,high-performance HTTP Server and reverse proxy.
# program:/usr/local/nginx/sbin/nginx
# config:/usr/local/nginx/conf/nginx.conf
# pidfile:/usr/local/nginx/logs/nginx.pid
# Synopsis:
#        nginx [--help] [--version] {start|stop|restart|reload|status|update}
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
# Define variable
nginx=/usr/local/nginx/sbin/nginx
pidfile=/usr/local/nginx/nginx.pid
PROGRAM=`basename $0`
VERSION=1.0
# Functions
usage(){
    echo "Usage: $PROGRAM [--help] [--version] {start|stop|restart|reload|status|update}"
}
version(){
    echo "Version:$VERSION"
}
start(){
if[ -e $pidfile ]
   then
    echo "Nginx already running..."
   else
    echo -e "Starting Nginx:"
    action "nginx start ..."/bin/true
    /usr/local/nginx/sbin/nginx
    echo -e "nginx is OK"
fi
}
stop(){
if[ -e $pidfile ]
   then
    echo -e "Stopping Nginx: kill nginx"
    kill -QUIT `cat ${pidfile}`
    echo -e "OK"
    action "nginx stop ..."/bin/true
    else
    echo "Nginx already stopped..."
fi
}
reload(){
if[ -e $pidfile ]
   then
    echo -e "Reloading Nginx: reload "
    kill -HUP `cat ${pidfile}`
    action "nginx reload OK "/bin/true
else
    echo "Nginx is not running..."
fi
}
status(){
    if[ -e $pidfile ]
       then
        PID=`cat $pidfile`
        echo  "Nginx (pid $PID) is running..."
        action "nginx status OK "/bin/true
       else
        echo  "Nginx is stopped"
    fi
}
update(){
if[ -e $pidfile ]
   then
    echo -e "Updateing Nginx:  nginx update"
    kill -USR2 `cat ${pidfile}`
    action "nginx update OK !!! "/bin/true
else
    echo "Nginx is not running..."
fi
}
if[ $# -gt 0]
   then
    case$1in
        start)
            start
            ;;
     stop)
           stop
           ;;
       restart)
           stop
           start
           ;;
       reload)
           reload
           ;;
       status)
           status
           ;;
       update)
           update
           ;;
       --help)
           usage
           ;;
       --version)
           version
           ;;
       *)
           usage
   esac
  else
   usage
fi


cp nginxd /etc/init.d/nginx
chkconfig --add nginx
service nginx restart




memcached 脚本:

启动脚本:

#!/bin/bash
# author:kuangl
# date:2013-05-30
# description: Starts and stops the Memcached services.
# pidfile: /tmp/memcached1.pid
# config:  /usr/local/memcached
# chkconfig: - 55 45
# source function library
. /etc/rc.d/init.d/functions
memcached="/usr/local/memcached/bin/memcached"
[ -e $memcached ] || exit 1
start()
{
echo "Starting memcached:"
daemon $memcached -d -m 2048 -u root -l 127.0.0.1 -p 11211 -c 10240 -P /tmp/memcached1.pid
}
stop()
{
echo "Shutting down memcached"
killproc memcached
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?


memcached 检测脚本:

这个脚本要配合crontab 来使用

#!/bin/bash
#Func:test memcached dead  reboot memcached
#date:2014/03/27
#BY:renzhenxing
#version:v0.1
mem=`ps -ef | grep mem | grep "mem" | egrep -v "vmmemctl|grep"| wc -l`
if [ $mem -eq 1 ];then
 echo  "mem is ok!!!"
 exit 0
else
 echo  "mem is dead !"
 /usr/local/memcached/bin/memcached -d -m 2048 -u root -l 127.0.0.1 -p 11211 -c 10240 -P /tmp/memcached1.pid
fi
~




























你可能感兴趣的:(nginx,memcached,检测,启动脚本)