#命令的位置 CMD="java" #参数空格隔开 ARGS=" -jar /opt/register-1.0.0.jar" #命令日志文件 LOG_FILE="./start.log" #pid文件 PID_FILE="./PID" start() { if [ -f $PID_FILE ]; then echo -n "process has run at " cat $PID_FILE exit 1 fi echo "start..." nohup $CMD $ARGS > $LOG_FILE 2>&1 & pid=$! kill -0 $pid if [ $? -eq "0" ]; then echo "process has running at $pid" echo $pid > $PID_FILE else echo "process start faild!" pid="" fi tail -f $LOG_FILE } stop() { echo "stop..." if [ -f $PID_FILE ]; then pid=$(cat $PID_FILE) kill -9 $pid rm -f $PID_FILE fi echo "success" } restart() { stop start } status() { pid_file=$(readlink -f $PID_FILE) if [ -f $pid_file ]; then pid=$(cat $pid_file) kill -0 $pid if [ $? -eq "0" ]; then echo "process has run at $pid" else echo "pid file:$pid_file exists,but process is not running!" fi else echo "process is not running!" fi } case $1 in start) start ;; stop) stop ;; restart) restart ;; status) status ;; *) echo "Usage command:start|stop|restart|status" exit 1 esac exit 0