脚本内容:
#!/bin/bash
cd `pwd`
app_name="tt"
start() {
source /etc/profile
status >/dev/null
if [[ $? -eq 0 ]]; then
echo "ERR. already running..."
return 1
fi
nohup java -Xmx512m -Xms256m -jar $1 --logging.config=$2 2>&1>/dev/null &
}
stop() {
status >/dev/null
if [[ $? -eq 0 ]]; then
read -r -p "Are you sure to stop this process?Y/N" input
if [[ ${input} == "Y" ]]; then
ps -ef | grep $app_name | grep -v grep | awk '{print $2}' | xargs -I {} kill {}
echo "stoped"
else
echo "you canceled stop operation."
fi
else
echo "stop err. not run."
fi
}
status() {
n=`ps -ef | grep $app_name | grep -v grep | wc -l`
if [[ $n -eq 1 ]]; then
echo "running"
return 0
else
echo "precess num is ${n}. not run or run too much"
return 1
fi
}
case $1 in
"start")
start $2 $3
;;
"stop")
stop
;;
"status")
status
;;
*)
echo "ERR. USE: $0 start \${jar_name} \${conf_file}|status|stop"
esac
启动命令:
./app.sh start xxx.jar logback-spring.xml
停止命令:
./app.sh stop