java程序脚本和tomcat脚本

java脚本

#!/bin/bash
# chkconfig: 345 99 1
# description: java progress
# processname: java
# authority :amos.lu
export PAHT=$PATH:/bin:/usr/bin:/usr/sbin:/sbin
export JAVA_HOME=/usr/local/jdk1.6.0_16
export JRE_HOME=/usr/local/jdk1.6.0_16
export LOGS_USER=root
export LOGS_HOME=/data/app/logs.playvip
export OPT="-jar -server -Xms512m -Xmx1024m"
export JAVA="/usr/local/jdk1.6.0_16/bin/java"
export NOHUP="/usr/bin/nohup"
. /etc/init.d/functions
#[ -d LOGS_HOME ] || { echo " sales requires LOGS_HOME"; exit 1; }
JAR=`ls $LOGS_HOME|grep jar|grep -v grep|head -n1`
usage() {
        echo "Usage: $0  {start|stop|restart|status}"
        exit 2
}
function start()
{
        if ps -ef | grep "$JAR" | grep -v grep >/dev/null
        then
                [ $? -eq 0 ] && echo "$JAR is already running.."
        else
                $NOHUP $JAVA $OPT $LOGS_HOME/$JAR   >>$LOGS_HOME/nohup.out 2>&1 &
                if [ $? -eq 0 ]
                then
                        echo -e "[ \e[1;32m OK \e[0m ]"
                else
                        echo -e "[ \e[1;31m failed \e[0m ]"
                fi
        fi
}
function stop()
{
        if ps -ef | grep -w "$JAR" | grep -v grep|awk '{print $2}'>/dev/null
        then
                ps auxw|grep  $JAR|grep -v grep |awk '{print $2}'|xargs kill -9 &>/dev/null
                if [ $? -eq 0 ]
                then
                        echo -e "[ \e[1;32m OK \e[0m ]"
                else
                        echo -e "[ \e[1;31m failed \e[0m ]"
                fi
        fi
}
function status()
{
        if ps -ef |grep  -w "$JAR"|grep -v grep >/dev/null
        then
                echo "$JAR is aleady running.."
        else
                echo "$JAR is not running.."
        fi
}
case $1 in
        start)
        start
        ;;
        stop)
        stop
        ;;
        status)
        status
        ;;
        restart)
        stop
        start
        ;;
        *)
        usage
        ;;
esac
exit 0

tomcat脚本

#!/bin/bash
# chkconfig: 345 99 1
# description: Tomcat6 service
# processname: java
      
# Get LSB functions
. /etc/init.d/functions
export PAHT=$PATH:/bin:/usr/bin:/usr/sbin:/sbin
export JAVA_HOME=/data/soft/jdk-7u21
export JRE_HOME=/data/soft/jdk-7u21
export PORT=80
export TOMCAT_USER=root
export CATALINA_HOME=/data/soft/tomcat_$PORT
export CATALINA_PID=$CATALINA_HOME/tomcat.pid
      
[ -d "$CATALINA_HOME" ] || { echo "Tomcat requires $CATALINA_HOME."; exit 1; }
usage() {
        echo "Usage: $0  {start|stop|restart|status|memcached_flush}"
        exit 2
}
memcached_flush()
{
        for i in `seq 1 1`
        do
                printf "flush_all\r\n"|nc 127.0.0.1 11212
                sleep 1
        done
}
      
case $1 in
      
    start|run)
    echo -n "Tomcat $1  :"
    if su - $TOMCAT_USER -c "$CATALINA_HOME/bin/catalina.sh $1 >/dev/null 2>&1"
    then
        echo -e "[ \e[1;32m OK \e[0m ]"
    else
         echo -e "[ \e[1;31m failed \e[0m ]"
    fi
    ;;
    stop)
        ps -ef |grep $PORT|grep -v grep && ps -ef |grep $PORT|grep -v grep |awk '{print $2}'|xargs kill -9 &> /dev/null
        if [ $? -eq 0 ]
        then
                echo -e "[ \e[1;32m OK \e[0m ]"
        else
                echo -e "[ \e[1;31m failed \e[0m ]"
        fi
         rm -f $CATALINA_PID
        ;;
    restart)
    $0 stop
    $0 start
    ;;
      
    status)
    if [ -f "$CATALINA_PID" ]; then
        read kpid < "$CATALINA_PID"
        if kill -0  $kpid 2>&1 >/dev/null; then
            echo " Tomcat is already running at ${kpid}"
        else
            echo "$CATALINA_PID found, but $kpid is not running"
        fi
        unset kpid
    else
        echo "Tomcat is stopped"
    fi
        ;;
    *)
        usage
    ;;
esac 
exit 0


你可能感兴趣的:(java程序脚本和tomcat脚本)