示例:
#!/bin/bashLANG="zh_CN.UTF-8"APP_HOME=$(echo `pwd` | sed 's/bin//')APPPIDFILE=$APP_HOME/app.pidcase $1 instart) echo "Starting server... " HEAP_MEMORY=512m PERM_MEMORY=64m JMX_PORT=8888 JMX_HOST=1.1.1.1 JAVA_OPTS="-server -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.EPollSelectorProvider -XX:+HeapDumpOnOutOfMemoryError -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false " shift ARGS=($*) for ((i=0; i<${#ARGS[@]}; i++)); do case "${ARGS[$i]}" in -D*) JAVA_OPTS="${JAVA_OPTS} ${ARGS[$i]}" ;; -Heap*) HEAP_MEMORY="${ARGS[$i+1]}" ;; -Perm*) PERM_MEMORY="${ARGS[$i+1]}" ;; -JmxPort*) JMX_PORT="${ARGS[$i+1]}" ;; -JmxHost*) JMX_HOST = "${ARGS[$i+1]}" ;; esac done JAVA_OPTS="${JAVA_OPTS} -Xms${HEAP_MEMORY} -Xmx${HEAP_MEMORY} -XX:PermSize=${PERM_MEMORY} -XX:MaxPermSize=${PERM_MEMORY} -Dcom.sun.management.jmxremote.port=${JMX_PORT} -Djava.rmi.server.hostname=${JMX_HOST} -Dapp.home=${APP_HOME}" echo "start jvm args ${JAVA_OPTS}" nohup java -classpath .:./aa-media-2.0.0.jar:$CLASSPATH $JAVA_OPTS com.aaa.media.aaaMediaServer& echo $! > $APPPIDFILE echo STARTED ;;stop) echo "Stopping server ... " if [ ! -f $APPPIDFILE ] then echo "error: count not find file $APPPIDFILE" exit 1 else kill -15 $(cat $APPPIDFILE) rm $APPPIDFILE echo STOPPED fi ;;*) echo "Please enter start|stop ... " ;;esacexit 0