#/bin/sh
# kill serversocket pid
//获取当前进程pid
#ps -ef | grep java | grep com.xxx | awk '{print $2}'| xargs -p kill
// $2获取 输入的第二个参数
jarFile=$2
usage(){
echo "Usage: {start|stop|restart}"
exit 1
}
get_pid(){
pid=`ps -ef | grep java | grep com.xxx | awk '{print $2}'`
}
is_exist(){
get_pid
if [ -z "${pid}" ];then
return 1
else
return 0
fi
}
start(){
is_exist
if [ $? -eq 0 ]; then
echo "已经正在运行了 pid=${pid}"
else
if [ -s ${jarFile} ]; then
`nohup java -Xms512m -Xmx512m -jar ${jarFile} >schoolWeb.out 2>&1 &`
get_pid
echo "jar包已发布 pid= ${pid}"
else
echo "请输入正确的jar包名"
fi
fi
}
stop(){
is_exist
if [ $? -eq "0" ]; then
kill $pid
echo "已杀死进程 ${pid}..."
else
echo "没有运行"
fi
# ps -ef | grep java | grep com.dchip.school.serverSocket | awk '{print $2}'| xargs -p kill
}
status(){
is_exist
if [ $? -eq "0" ]; then
echo "schoolWeb 在运行 pid=${pid}"
else
echo "schoolWeb 没有运行"
fi
}
restart(){
stop
sleep 3
start
}
case $1 in
"start")
start
;;
"stop")
stop
;;
"restart")
restart
;;
"status")
status
;;
*)
usage
esac