java 服务常用启动脚本

[root@changshan bike-access-0.0.1-SNAPSHOT]# cat run.sh 
#!/bin/bash
JAVA_OPTS=""
DEBUG="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=2345"
MAIN_CLASS=com.ziytek.bike.access.BikeAccessServer
if [ "$1" = "b" ] ; then
	nohup java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start >/dev/null 2>&1 &
elif [ "$1" = "d" ] ; then
	java $JAVA_OPTS $DEBUG -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start 
else
	java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $1 $2 $3 $4 start
	
	

[root@changshan bike-jms-0.0.1-SNAPSHOT]# cat run.sh 
#!/bin/bash
JAVA_OPTS=""
MAIN_CLASS=com.ziytek.bike.jms.BikeJmsServer
if [ "$1" = "b" ] ; then
	nohup java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start >/dev/null 2>&1 &
else
	java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $1 $2 $3 $4 start
fi


[root@changshan bike-ba-web-0.0.1-SNAPSHOT]# cat run.sh 
#!/bin/bash
JAVA_OPTS=""
DEBUG="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=2345"
MAIN_CLASS=com.ziytek.bikeba.web.BikeBAServiceApplication
if [ "$1" = "b" ] ; then
	nohup java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start >/dev/null 2>&1 &
elif [ "$1" = "d" ] ; then
	java $JAVA_OPTS $DEBUG -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start 
else
	java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $1 $2 $3 $4 start


[root@changshan message-server-0.0.1-SNAPSHOT]# cat run.sh 
#!/bin/bash
JAVA_OPTS=""
DEBUG="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=2345"
MAIN_CLASS=com.ziytek.message.server.UMServer
if [ "$1" = "b" ] ; then
	nohup java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start >/dev/null 2>&1 &
elif [ "$1" = "d" ] ; then
	java $JAVA_OPTS $DEBUG -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start 
else
	java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $1 $2 $3 $4 start
fi


容器
# cat run.sh
#!/bin/bash
JAVA_OPTS=""
DEBUG="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=2345"
MAIN_CLASS=com.ziytek.bikeba.web.BikeBAServiceApplication

function stop(){
    echo "Stop $MAIN_CLASS"
    boot_id=`ps -ux |grep java|grep $MAIN_CLASS|grep -v grep|awk '{print $2}'`
    count=`ps -ux |grep java|grep $MAIN_CLASS|grep -v grep|wc -l`

    if [ $count != 0 ];then
        kill $boot_id
        count=`ps -ux |grep java|grep $MAIN_CLASS|grep -v grep|wc -l`

        boot_id=`ps -ux |grep java|grep $MAIN_CLASS|grep -v grep|awk '{print $2}'`
        kill -9 $boot_id
        fi
}

function start(){
    echo "Start $MAIN_CLASS"
        nohup java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start >/dev/null 2>&1 &
    sleep 1
    status;
}

function status(){
    count=`ps -ux |grep java|grep $MAIN_CLASS|grep -v grep|wc -l`
    boot_id=`ps -ux |grep java|grep $MAIN_CLASS|grep -v grep|awk '{print $2}'`

    if [ $count != 0 ];then
        echo "$MAIN_CLASS is running... PID is $boot_id"
    else
        echo "$MAIN_CLASS is not running..."
    fi
}

if [ "$1" = "b" ] ; then
    start;
elif [ "$1" = "d" ] ; then
        java $JAVA_OPTS $DEBUG -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start
elif [ "$1" = "status" ] ; then
    status;
elif [ "$1" = "stop" ] ; then
    stop;
elif [ "$1" = "restart" ] ; then
    stop;
    sleep 1
    start;
    tail -f logs/um_info.log
else
        java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $1 $2 $3 $4 start
fi

# cat run.bat
set JAVA_OPTS=-Dfile.encoding=UTF-8
set DEBUG=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=2345
set MAIN_CLASS=com.ziytek.bikeba.web.BikeBAServiceApplication
java %JAVA_OPTS% -Dmain.class=%MAIN_CLASS% -classpath .;nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap %1 %2 %3 start

#!/bin/bash
DEBUG="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=2345"
MAIN_CLASS=com.ziytek.bikeca.web.BikeCAServiceApplication

function stop(){
    echo "Stop $MAIN_CLASS"
    boot_id=`ps -ef |grep java|grep $MAIN_CLASS|grep -v grep|awk '{print $2}'`
    count=`ps -ef |grep java|grep $MAIN_CLASS|grep -v grep|wc -l`

    if [ $count != 0 ];then
        kill $boot_id
        count=`ps -ef |grep java|grep $MAIN_CLASS|grep -v grep|wc -l`

        boot_id=`ps -ef |grep java|grep $MAIN_CLASS|grep -v grep|awk '{print $2}'`
        kill -9 $boot_id
        fi
}

function start(){
    echo "Start $MAIN_CLASS"
	nohup java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start >/dev/null 2>&1 &
    sleep 1
    status;
}

function status(){
    count=`ps -ef |grep java|grep $MAIN_CLASS|grep -v grep|wc -l`
    boot_id=`ps -ef |grep java|grep $MAIN_CLASS|grep -v grep|awk '{print $2}'`

    if [ $count != 0 ];then
        echo "$MAIN_CLASS is running... PID is $boot_id"
    else
        echo "$MAIN_CLASS is not running..."
    fi
}

if [ "$1" = "b" ] ; then
    stop;
    sleep 1
    start;
elif [ "$1" = "d" ] ; then
	java $JAVA_OPTS $DEBUG -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start
elif [ "$1" = "status" ] ; then
    status;
elif [ "$1" = "stop" ] ; then
    stop;
elif [ "$1" = "restart" ] ; then
    stop;
    sleep 1
    start;
else
	java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $1 $2 $3 $4 start
fi




正式run.sh
#!/bin/bash
DEBUG="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=2345"
MAIN_CLASS=com.ziytek.bikeca.web.BikeCAServiceApplication

function stop(){
    echo "Stop $MAIN_CLASS"
    boot_id=`ps -ef |grep java|grep $MAIN_CLASS|grep -v grep|awk '{print $2}'`
    count=`ps -ef |grep java|grep $MAIN_CLASS|grep -v grep|wc -l`

    if [ $count != 0 ];then
        kill $boot_id
        count=`ps -ef |grep java|grep $MAIN_CLASS|grep -v grep|wc -l`

        boot_id=`ps -ef |grep java|grep $MAIN_CLASS|grep -v grep|awk '{print $2}'`
        kill -9 $boot_id
        fi
}

function start(){
    echo "Start $MAIN_CLASS"
        nohup java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start >/dev/null 2>&1 &
    sleep 1
    status;
}

function status(){
    count=`ps -ef |grep java|grep $MAIN_CLASS|grep -v grep|wc -l`
    boot_id=`ps -ef |grep java|grep $MAIN_CLASS|grep -v grep|awk '{print $2}'`

    if [ $count != 0 ];then
        echo "$MAIN_CLASS is running... PID is $boot_id"
    else
        echo "$MAIN_CLASS is not running..."
    fi
}

if [ "$1" = "b" ] ; then
    stop;
    sleep 1
    start;
elif [ "$1" = "d" ] ; then
        java $JAVA_OPTS $DEBUG -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $2 $3 $4 $5 start
elif [ "$1" = "status" ] ; then
    status;
elif [ "$1" = "stop" ] ; then
    stop;
elif [ "$1" = "restart" ] ; then
    stop;
    sleep 1
    start;
else
        java $JAVA_OPTS -Dmain.class=$MAIN_CLASS -classpath .:nest-boot-0.0.1-SNAPSHOT.jar com.ziytek.startup.Bootstrap $1 $2 $3 $4 start
fi