#!/bin/sh
export common_service_enable=true
export business_service_enable=true
export xiaopandian_web_enable=true
export common_service=/mnt/xiaopandian-api/dev-common-service.jar
export business_service=/mnt/xiaopandian-api/dev-business-service.jar
export xiaopandian_web=/mnt/xiaopandian-api/dev-xiaopandian-web.jar
export common_service_port=17001
export business_service_port=17002
export xiaopandian_web_port=17003
case "$1" in
start)
if($common_service_enable);then
## 啟動(dòng)timeservice
echo "--------common_service 開(kāi)始啟動(dòng)--------------"
nohup java -jar $common_service >/dev/null 2>&1 &
common_service_pid=`lsof -i:$common_service_port|grep "LISTEN"|awk '{print $2}'`
until [ -n "$common_service_pid" ]
do
common_service_pid=`lsof -i:$common_service_port|grep "LISTEN"|awk '{print $2}'`
done
echo "common_service pid is $common_service_pid"
echo "--------common_service 啟動(dòng)成功--------------"
fi
if($business_service_enable);then
## 啟動(dòng)business_service
echo "--------business_service 開(kāi)始啟動(dòng)--------------"
nohup java -jar $business_service >/dev/null 2>&1 &
business_service_pid=`lsof -i:$business_service_port|grep "LISTEN"|awk '{print $2}'`
until [ -n "$business_service_pid" ]
do
business_service_pid=`lsof -i:$business_service_port|grep "LISTEN"|awk '{print $2}'`
done
echo "business_service pid is $business_service_pid"
echo "--------business_service 啟動(dòng)成功--------------"
fi
if($xiaopandian_web_enable);then
## 啟動(dòng)ftpschedule
echo "--------xiaopandian_web 開(kāi)始啟動(dòng)--------------"
nohup java -jar $xiaopandian_web >/dev/null 2>&1 &
xiaopandian_web_pid=`lsof -i:$xiaopandian_web_port|grep "LISTEN"|awk '{print $2}'`
until [ -n "$xiaopandian_web_pid" ]
do
xiaopandian_web_pid=`lsof -i:$xiaopandian_web_port|grep "LISTEN"|awk '{print $2}'`
done
echo "xiaopandian_web pid is $xiaopandian_web_pid"
echo "--------xiaopandian_web 啟動(dòng)成功--------------"
fi
echo "===startAll success==="
;;
stop)
## 殺掉common_service
P_ID=`ps -ef | grep -w ${common_service##*/} | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "===common_service process not exists or stop success"
else
kill -9 $P_ID
echo "common_service killed success"
fi
## 殺掉business_service
P_ID=`ps -ef | grep -w ${business_service##*/} | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "===business_service process not exists or stop success"
else
kill -9 $P_ID
echo "business_service killed success"
fi
## 殺掉xiaopandian_web
P_ID=`ps -ef | grep -w ${xiaopandian_web##*/} | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "===xiaopandian_web process not exists or stop success"
else
kill -9 $P_ID
echo "xiaopandian_web killed success"
fi
echo "===stopAll success==="
;;
restart)
$0 stop
sleep 2
$0 start
echo "===restartAll success==="
;;
check)
## 檢查common_service
P_ID=`ps -ef | grep -w ${common_service##*/} | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "===common_service process not alive"
else
echo "===common_service process alive"
fi
## 檢查business_service
P_ID=`ps -ef | grep -w ${business_service##*/} | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "===business_service process not alive"
else
echo "===business_service process alive"
fi
## 檢查xiaopandian_web
P_ID=`ps -ef | grep -w ${xiaopandian_web##*/} | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "===xiaopandian_web process not alive"
else
echo "===xiaopandian_web process alive"
fi
echo "===check finished==="
;;
esac
exit 0
二、過(guò)程將.sh腳本拖到服務(wù)器
將.sh文件賦予權(quán)限
chmod 775 XXX.sh
執(zhí)行
# 啟動(dòng)
./XXX.sh start
# 停止
./XXX.sh stop
# 檢查
./XXX.sh check
# 重啟
./XXX.sh restart
Linux執(zhí)行.sh文件,提示No such file or directory的問(wèn)題
原因:在windows中寫(xiě)好shell腳本測(cè)試正常,但是上傳到 Linux 上以腳本方式運(yùn)行命令時(shí)提示No such file or directory錯(cuò)誤,那么一般是文件格式是dos格式的緣故,改成unix 格式即可。一般有如下幾種修改辦法。
解決辦法:
用vim打開(kāi)該sh文件,輸入:
:set ff
回車,顯示fileformat=dos,重新設(shè)置下文件格式:
:set ff=unix
保存退出:
:wq
再執(zhí)行,竟然可以了
解決Ubuntu下編譯.sh文件報(bào)錯(cuò) “[: XXXX: unexpected operator”
原因:因?yàn)閁buntu默認(rèn)的sh是連接到dash的,dash跟bash的不兼容所以出錯(cuò)了。
解決辦法:命令行輸入后,選擇NO
sudo dpkg-reconfigure dash
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧