02-exe_once
1. 一次性停启脚本
exe.sh 和 jar 在同一文件夹内,日志文件为nohup.log
#!/bin/bash
# 修改jar名称即可
package_name=ooxx-SNAPSHOT.jar
jvm_opt="-Xms512m -Xmx512m"
# 入参检查
if [ $# -ne 1 ]; then
echo -e "-->Error! Please enter the param, such as \033[33m [start/status/stop/restart] or [1/2/3/4] \033[0m"
echo -e "-->Example : ./exe.sh start"
exit 1
fi
function Start() {
nohup java -jar $jvm_opt $package_name >nohup.log 2>&1 &
sleep 5
echo "进程状态:"
Status
}
function Status() {
echo "进程状态:"
ps -ef | grep $package_name | grep -v grep
}
function Stop() {
pid=$(ps -ef | grep $package_name | grep -v grep | awk {'print $2'})
kill -9 $pid
}
function Restart() {
Stop
Start
}
if [ $1 == "start" ] || [ $1 == "1" ]; then
Start
elif [ $1 == "status" ] || [ $1 == "2" ]; then
Status
elif [ $1 == "stop" ] || [ $1 == "3" ]; then
Stop
elif [ $1 == "restart" ] || [ $1 == "4" ]; then
Restart
else
echo -e "--> \033[33m The param you enter is wrong! Please retry! \033[0m" $1
echo -e "--> \033[33m The param is [start/status/stop/restart] or [1/2/3/4] \033[0m"
fi