set ff=unix
#!/bin/basha=`date +%Y%m%d`;#获取当前时间start(){ echo "start project..." if [[ ! -d ./pid/ ]]; then mkdir -p pid; fi; if [[ ! -d ./serverLog/ ]]; then mkdir -p serverLog; fi; #注意:必须有&让其后台执行,否则没有pid生成 java -Dfile.encoding=utf-8 -jar nelda-center.jar nelda-center > ./serverLog/{$a}_nelda-center.log & echo $! > ./pid/nelda-center.pid # 将jar包启动对应的pid写入文件中,为停止时提供pid java -Dfile.encoding=utf-8 -jar nelda-gate.jar nelda-gate > ./serverLog/{$a}_nelda-gate.log 2>&1 & echo $! > ./pid/nelda-gate.pid java -Dfile.encoding=utf-8 -jar nelda-auth.jar nelda-auth > ./serverLog/{$a}_nelda-auth.log 2>&1 & echo $! > ./pid/nelda-auth.pid java -Dfile.encoding=utf-8 -jar nelda-business.jar nelda-business > ./serverLog/{$a}_nelda-business.log 2>&1 & echo $! > ./pid/nelda-business.pid java -Dfile.encoding=utf-8 -jar nelda-admin.jar nelda-admin > ./serverLog/{$a}_nelda-admin.log 2>&1 & echo $! > ./pid/nelda-admin.pid echo "start project end..."}stop(){
echo "stop project..." PID=$(cat ./pid/nelda-center.pid) kill -9 $PID PID=$(cat ./pid/nelda-gate.pid) kill -9 $PID PID=$(cat ./pid/nelda-auth.pid ) kill -9 $PID PID=$(cat ./pid/nelda-business.pid) kill -9 $PID PID=$(cat ./pid/nelda-admin.pid) kill -9 $PID echo "stop project end..." rm -rf ./pid}#停止指定的服务stopAppoint(){ echo 'Stop the specified service' echo 'stop nelda-center-------->1' echo 'stop nelda-gate---------->2' echo 'stop nelda-auth---------->3' echo 'stop nelda-business------>4' echo 'stop nelda-admin--------->5' read aNum case $aNum in 1) echo 'your choose nelda-center' PID=$(cat ./pid/nelda-center.pid) kill -9 $PID rm -rf ./pid/nelda-center.pid exit; ;; 2) echo 'your choose nelda-gate' PID=$(cat ./pid/nelda-gate.pid) kill -9 $PID rm -rf ./pid/nelda-gate.pid exit; ;; 3) echo 'your choose nelda-auth' PID=$(cat ./pid/nelda-auth.pid) kill -9 $PID rm -rf ./pid/nelda-auth.pid exit; ;; 4) echo 'your choose nelda-business' PID=$(cat ./pid/nelda-business.pid) kill -9 $PID rm -rf ./pid/nelda-business.pid exit; ;; 5) echo 'your choose nelda-admin' PID=$(cat ./pid/nelda-admin.pid) kill -9 $PID rm -rf ./pid/nelda-admin.pid exit; ;; *) echo 'There are no numbers you enter' exit 1 ;; esac}
#启动指定的服务
startAppoint(){ echo 'Start the specified service' echo 'Start nelda-center----------->1' echo 'Start nelda-gate------------->2' echo 'Start nelda-auth------------->3' echo 'Start nelda-business--------->4' echo 'Start nelda-admin------------>5' if [[ ! -d ./pid/ ]]; then mkdir -p pid; fi; read aNum case $aNum in 1) echo 'your choose nelda-center' #注意:必须有&让其后台执行,否则没有pid生成 java -jar nelda-center.jar nelda-center > ./serverLog/{$a}_nelda-center.log & #将jar包启动对应的pid写入文件中,为停止时提供pid echo $! > ./pid/nelda-center.pid ;; 2) echo 'your choose nelda-gate' java -jar nelda-gate.jar nelda-gate> ./serverLog/{$a}_nelda-gate.log 2>&1 & echo $! > ./pid/nelda-gate.pid ;; 3) echo 'your choose nelda-auth' java -jar nelda-auth.jar > ./serverLog/{$a}_nelda-auth.log 2>&1 & echo $! > ./pid/nelda-auth.pid ;; 4) echo 'your choose nelda-business' java -jar nelda-business.jar > ./serverLog/{$a}_nelda-business.log 2>&1 & echo $! > ./pid/nelda-business.pid ;; 5) echo 'your choose nelda-admin' java -Dfile.encoding=utf-8 -jar nelda-admin.jar > ./serverLog/{$a}_nelda-admin.log 2>&1 & echo $! > ./pid/nelda-admin.pid ;; *) echo 'There are no numbers you enter' exit 1 ;; esac}restart(){
stop sleep 1 start}echo 'choose your number'
echo 'start all server----->1'echo 'start appoint server----->2'echo 'stop all server----->3'echo 'stop appoint server----->4'echo 'restart all server----->5'read aNumcase $aNum in 1) echo 'your choose 1' start; exit; ;; 2) echo 'your choose 2' startAppoint; exit; ;; 3) echo 'your choose 3' stop; exit; ;; 4) echo 'your choose 4' stopAppoint; exit; ;; 5) echo 'your choose 5' restart exit; ;; *) echo 'There are no numbers you enter' exit 1 ;;esac