linux的java服务启停脚本

linux的java服务启停脚本

APP_NAME=xxxx-1.0-SNAPSHOT.jar

pid=0
checkpid() {
javaps=jps -l | grep $APP_NAME
if [ -n “$javaps” ]; then
pid=echo $javaps | awk '{print $1}'
else
pid=0
}

start() {
checkpid
if [ p s i d − n e 0 ] ; t h e n e c h o " psid -ne 0 ]; then echo " psidne0];thenecho"APP_NAME already started"
else
echo “Starting $APP_NAME …”
nohup java -jar $APP_NAME > $APP_NAME'.out' 2>&1 &
checkpid
if [ p i d − n e 0 ] ; t h e n e c h o " pid -ne 0]; then echo " pidne0];thenecho"APP_NAME start success"
else
echo “$APP_NAME start faild”
fi
fi
}

stop() {
checkpid
if [ $pid -ne 0 ]; then
echo “Stoping $APP_NAME…”
kill -9 p i d i f [ pid if [ pidif[? -eq 0 ]; then
echo “ A P P N A M E s t o p s u c c e s s " e l s e e c h o " APP_NAME stop success" else echo " APPNAMEstopsuccess"elseecho"APP_NAME stop faild”
fi
else
echo “$APP_NAME already stoped”
fi
}

case “$1” in
‘start’)
start
;;
‘stop’)
stop
;;
‘restart’)
stop
start
;;
*) # 其他任何情况

echo “help: $0 {start|stop|restart}”
echo "例子: ./deploy start
exit 1
esac
exit 0

你可能感兴趣的:(linux,java,运维)