jar 运行脚本
程序员文章站
2022-05-10 09:40:15
...
#!/bin/sh
program=homestay-web.jar
execute=/usr/java/jdk1.8.0_131/bin/java
command=homestay-web
if [ "$1" = "" ];
then
echo -e "Execute Shell like: $command.sh {start|stop|restart|status} "
exit 1
fi
function start()
{
count=`ps -ef |grep java|grep $program|grep -v grep|wc -l`
if [ $count != 0 ];then
echo "$program is running..."
else
nohup $execute -jar $program > /dev/null 2>&1 &
echo "Start $program success..."
fi
}
function stop()
{
boot_id=`ps -ef |grep java|grep $program|grep -v grep|awk '{print $2}'`
count=`ps -ef |grep java|grep $program|grep -v grep|wc -l`
if [ $count != 0 ];then
kill $boot_id
sleep 1
count=`ps -ef |grep java|grep $program|grep -v grep|wc -l`
if [ $count != 0 ];then
boot_id=`ps -ef |grep java|grep $program|grep -v grep|awk '{print $2}'`
kill -9 $boot_id
fi
echo "Stop $program success..."
else
echo "$program is stopped..."
fi
}
function restart()
{
stop
start
}
function status()
{
count=`ps -ef |grep java|grep $program|grep -v grep|wc -l`
if [ $count != 0 ];then
boot_id=`ps -ef |grep java|grep $program|grep -v grep|awk '{print $2}'`
echo "$program is running... [$boot_id]"
else
echo "$program is stopped..."
fi
}
case $1 in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)
esac
转载于:https://my.oschina.net/jeebey/blog/1930701