Shell脚本:jar包启停
2023-09-11 14:19:56 时间
在日常工作中经常会启停服务,故整理成脚本,方便操作。
shell脚本内容如下:(exe.sh)
#!/bin/bash package_name=flink-0.0.1-SNAPSHOT.jar #current_path=/data #入参检查 if [ $# -ne 1 ]; then echo -e "-->Error! Please enter the param, such as \033[33m [start/status/stop/restart] or [1/2/3/4] \033[0m" echo -e "-->Example : ./exe.sh start" exit 1 fi function Start(){ nohup java -jar $package_name > nohup.log 2>&1 & sleep 2 echo "进程状态:" Status } function Status(){ echo "进程状态:" ps -ef | grep $package_name | grep -v grep } function Stop(){ pid=`ps -ef | grep $package_name | grep -v grep| awk {'print $2'}` kill -9 $pid } function Restart(){ Stop Start } if [ $1 == "start" ] || [ $1 == "1" ]; then Start elif [ $1 == "status" ] || [ $1 == "2" ]; then Status elif [ $1 == "stop" ] || [ $1 == "3" ]; then Stop elif [ $1 == "restart" ] || [ $1 == "4" ]; then Restart else echo -e "--> \033[33m The param you enter is wrong! Please retry! \033[0m" $1 echo -e "--> \033[33m The param is [start/status/stop/restart] or [1/2/3/4] \033[0m" fi
使用方法:
./exe.sh [start/status/stop/restart]
或者
./exe.sh [1/2/3/4]
相关文章
- Linux Shell脚本自动化编程实战- shell并发
- 获取shell脚本自身所在目录的Shell脚本分享
- 关于在android源码编译时引用第三方jar宝--需要在android.mk中配置
- Jar mismatch! Fix your dependencies的问题
- Linux Shell脚本自动化编程实战- shell并发
- 获取shell脚本自身所在目录的Shell脚本分享
- .jar包文件的生成与运行
- 如何处理Maven build时的error message Unable to locate the Javac Compiler in tools.jar
- 产生 java.lang.NoClassDefFoundError 的另一种意外情况:jar包部分的物理性损坏
- Maven自定义上传第三方包到3rd party(第三方无依赖jar和本地扩展类加入maven统一管理)
- 将自己的jar提交maven中央仓
- 20.第六章 Shell脚本编程基础入门 -- shell 脚本语言的基本用法(三)
- 19.第六章 Shell脚本编程基础入门 -- shell 脚本语言的基本用法(二)
- 18.第六章 Shell脚本编程基础入门 -- 编程基础和shell脚本语言的基本用法(一)
- 【已实现】服务器jar包启动脚本、shell脚本
- shell - 02 - Shell的转折点:流程与控制
- JAR包分享之Oracle(java)数据库11.2.0.4 JDBC驱动程序 jar包 ojdbc6.jar ojdbc5.jar