Linux自定义java程序运行脚本的命令

网友投稿 255 2022-11-01


Linux自定义java程序运行脚本的命令

以下脚本将启动mes-lastest.jar,并且:

1、开启远程调试支持,端口8899,

2、开启GC日志记录功能

3、程序发送OOM是Dump内存

用法如下:

Usage: ./run.sh {start|stop|restart|status|stop -f}Example: ./run.sh

示例:

ubuntu@ubuntu:~$ ^Cubuntu@ubuntu:~$ vim run.shubuntu@ubuntu:~$ ./run.sh startMaybe mes-lastest.jar is running, please check it...ubuntu@ubuntu:~$ ./run.sh stopThe mes-lastest.jar is stopping...ubuntu@ubuntu:~$ ./run.sh startThe mes-lastest.jar is starting...ubuntu@ubuntu:~$

#!/bin/bashappName=`ls|grep mes-lastest.jar$`if [ -z $appName ]then echo "Please check that this script and your jar-package is in the same directory!" exit 1fikillForceFlag=$2function start(){ count=`ps -ef |grep java|grep $appName|wc -l` if [ $count != 0 ];then echo "Maybe $appName is running, please check it..." else echo "The $appName is starting..." nohup java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8899 -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/ubuntu -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:/home/ubuntu/gc.log -Xms512M -Xmx1024G -Dserver.port=8080 -jar $appName > /dev/null 2>&1 & fi}function stop(){ appId=`ps -ef |grep java|grep $appName|awk '{print $2}'` if [ -z $appId ] then echo "Maybe $appName not running, please check it..." else echo -n "The $appName is stopping..." if [ "$killForceFlag" == "-f" ] then echo "by force" kill -9 $appId else echo kill $appId fi fi}function status(){ appId=`ps -ef |grep java|grep $appName|awk '{print $2}'` if [ -z $appId ] then echo -e "\033[31m Not running \033[0m" else echo -e "\033[32m Running [$appId] \033[0m" fi}function restart(){ stop for i in {3..1} do echo -n "$i " sleep 1 done echo 0 start}function usage(){ echo "Usage: $0 {start|stop|restart|status|stop -f}" echo "Example: $0 start" exit 1}case $1 in start) start;; stop) stop;; restart) restart;; status) status;; *) usage;;esac


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:操作系统迁移实战之Apache 2.4.39 移植
下一篇:如何使用Reactor完成类似Flink的操作
相关文章

 发表评论

暂时没有评论,来抢沙发吧~