linux下启动和关闭jar项目

1、自己将项目(比如用springboot框架写的项目)打包成jar包,然后我们需要将它用软件传输到linux版本的服务器上(服务器提前安装好JDK>=1.8)。

2、自己编写sh命令,用于启动和关闭项目,并打印日志信息到服务器本地。

1)、start_项目名.sh文件

#For shutting down the 你的项目名.jar
pid=$(ps -ef | grep 你的项目名.jar| grep -v "grep" | awk '{print $2}')
kill -9 $pid
echo "The 你的项目名.jar now has been shut down!"

#For starting the 你的项目名.jar
nohup java -jar 你的项目名.jar >你的项目日志名.output 2>&1 &
echo "The 你的项目名.jar now is running!"
tailf  你的项目日志名.output

2)、shutdown_项目名.sh文件

#For shutting down the 你的项目名.jar
pid=$(ps -ef | grep 你的项目名.jar| grep -v "grep" | awk '{print $2}')
kill -9 $pid
echo "The 你的项目名.jar now has been shut down!"

3、将你的项目jar包、start_项目名.sh、shutdown_项目名.sh放在服务器的某一个文件夹下(他三个处于同一个目录),此时,可以用控制台启动和关闭项目了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章