#!/usr/bin/env bash current_dir=$(cd "$(dirname "$0")"; pwd) cd $current_dir HOME=$current_dir #JAVA_HOME=/opt/jdk1.7.0_07 MAINCLASS="org.eclipse.jetty.start.Main" LIB_DIR="lib" CLASS_DIR="start.jar" JVM_ARGS="-Djetty.port=6220 -Dsolr.solr.home=solr -Dorg.eclipse.jetty.util.URI.charset=UTF-8" PRO_ARGS="" PROGRAM_NAME=solr PID_DIR="$HOME/start.d" jcommand="java" runtype="-classpath" APPEND_LIB=$HOME"/"$CLASS_DIR PID_NAME=$PROGRAM_NAME".pid" pid=$PID_DIR/$PID_NAME echo "CURRENT_DIR="$HOME #注意这个字符,不是',是`,数字键左边的那个键 filelist=`ls $HOME"/"$LIB_DIR` for f in $filelist do name=$HOME"/"$LIB_DIR"/"$f APPEND_LIB=$APPEND_LIB:$name done case $1 in 'start' ) mkdir -p "$PID_DIR" if [ -f "$pid" ]; then echo $pid existsed, pid: `cat $pid` if kill -0 `cat "$pid"` > /dev/null 2>&1; then echo $PROGRAM_NAME running as process `cat $pid`. Stop it first. exit 1 fi fi echo -n 'Starting : ' if $jcommand $JVM_ARGS $runtype $APPEND_LIB $MAINCLASS $PRO_ARGS > /dev/null 2>&1 & then echo $! > "$pid" echo 'OK' else echo 'Failed' fi ;; 'run' ) $jcommand $JVM_ARGS $runtype $APPEND_LIB $MAINCLASS $PRO_ARGS ;; 'classpath' ) echo $jcommand $JVM_ARGS $runtype $APPEND_LIB $MAINCLASS $PRO_ARGS ;; 'stop' ) if [ -f "$pid" ]; then if kill `cat "$pid"` > /dev/null 2>&1; then echo stopping $PROGRAM_NAME kill `cat "$pid"` rm $pid else echo No $PROGRAM_NAME to stop fi else echo No $PROGRAM_NAME to stop fi ;; 'list' ) ps aux | egrep '(PID|java|$PROGRAM_NAME)' ;; *) echo 'usage: `basename $0` {start|run|stop|list}' esac