We all know that the JVM itself provides a lot of commands for users to call. Sometimes we need to use these commands to write some scripts to execute our program. First, let's talk about the directory structure of the following script:
Bin script Storage
Lib dependent jar package Storage
Configuration file storage on which conf depends
Run the prepared JAR file in the current directory.
#!/bin/bashexport JAVA_HOME=/usr/javaexport PATH=$JAVA_HOME/bin:$PATH#-------------------------------------------------------------------# Mb Bootstrap Script #-------------------------------------------------------------------function main(){ # find Mb home. CURR_DIR=`pwd` cd `dirname "$0"`/.. RESV_HOME=`pwd` cd $CURR_DIR if [ -z "$RESV_HOME" ] ; then echo echo Must set RESV_HOME echo exit 1 fi pc=`ps -ef | grep "ThreadMore $1" | wc -l ` echo "process count:$pc" if [[ $pc -gt 1 ]]; then echo "last job havent finish,exit." exit 1 fi execute $1 $2}function execute(){ for i in $RESV_HOME/lib/*.jar; do CLASSPATH=$i:$CLASSPATH; done #echo RESV_HOME=$RESV_HOME CLASSPATH=$RESV_HOME/conf:$RESV_HOME/smack.jar:$CLASSPATH DEBUG_INFO=" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n" DEBUG="" if [ "$1" = "load" ] then MAIN_CLASS="www.smack.ThreadLocal $1"; DEFAULT_OPTS="-server -Xms10G -Xmx10G " ; else if [ "$1" = "check" ] then MAIN_CLASS="www.smack.ThreadLocal "; DEFAULT_OPTS="-server -Xms2G -Xmx2G" ; else MAIN_CLASS="www.smack.ThreadLocal $1 $2"; DEFAULT_OPTS="-server -Xms2000m -Xmx2000m -Xss128k" ; fi fi DEFAULT_OPTS="$DEFAULT_OPTS -Djava.awt.headless=true -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=10.10.10.7" DEFAULT_OPTS="$DEFAULT_OPTS -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=60" DEFAULT_OPTS="$DEFAULT_OPTS -DMB.home=\"$RESV_HOME\"" echo java $DEBUG $DEFAULT_OPTS -classpath $CLASSPATH $MAIN_CLASS java $DEBUG $DEFAULT_OPTS -classpath $CLASSPATH $MAIN_CLASS}main "4000" "40"
This article from the "Chen Yan Xi" blog, please be sure to keep this source http://chenyanxi.blog.51cto.com/4599355/1559651
Shell script to start the program