Files

72 lines
1.3 KiB
Bash
Raw Normal View History

2021-09-28 11:47:19 +08:00
#!/bin/bash
# date
# 替换为你自己的执行程序
APP_NAME=main
# 项目的路径(替换成项目的路径)
PROJECT_LOCATION=/home/www/SciencesServer
usage() {
echo "Usage: sh 执行脚本.sh [start|stop|restart|status]"
exit 1
}
is_exist(){
pid=`ps -ef|grep ./$APP_NAME|grep -v grep|awk '{print $2}' `
#如果不存在返回1存在返回0
if [ -z "${pid}" ]; then
#return 1
proct=1
else
#return 0
proct=0
fi
}
start(){
is_exist
if [ $proct -eq 0 ]; then
echo "${APP_NAME} is already running. pid=${pid} ."
else
cd ${PROJECT_LOCATION}
#nohup java -Xms256m -Xmx256m -jar $APP_NAME > /dev/null 2>&1 &
nohup ./$APP_NAME > /dev/null 2>&1 &
echo "${APP_NAME} is start"
fi
}
stop(){
is_exist
if [ $proct -eq 0 ]; then
cd ${PROJECT_LOCATION}
kill -9 $pid
echo "${APP_NAME} is stop"
else
echo "${APP_NAME} is not running"
fi
}
status(){
is_exist
if [ $proct -eq 0 ]; then
echo "${APP_NAME} is running. pid is ${pid}"
else
echo "${APP_NAME} is not running."
fi
}
restart(){
stop
start
}
# 根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac