Chinaunix首页 | 论坛 | 博客
  • 博客访问: 323297
  • 博文数量: 50
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1387
  • 用 户 组: 普通用户
  • 注册时间: 2013-07-24 10:12
文章分类
文章存档

2014年(18)

2013年(32)

分类: Java

2014-03-25 15:03:51

ava脚本
   
#!/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: 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"
. /etc/init.d/functions
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
                su - $TOMCAT_USER bash -c "$CATALINA_HOME/bin/catalina.sh $1 >/dev/null 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
阅读(2644) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

CU博客助理2014-05-22 13:02:16

嘉宾点评:
将代码贴出来与大家分享这是open交流的一个很好地开端。如果能加上你的理解和应用场景就更好了。这样有利于总结加深你的理解,和相关朋友们交流时也能更深入一些。任何配置都是基于一定场景的最优化配置,如果把项目内容大概说一下,我可能会给更多的优化建议。(感谢您参与“原创博文评选”获奖结果即将公布)