Shell command to restart springboot project

Hello everyone, I am Xiongxiong. My WeChat public account is: Xiongxiong’s Little Classroom. Welcome to follow me.

Insert image description here

Preface

We all know that springbootwhen starting a project, the following process is required:

  1. Find the process id of a service
  2. Kill the process
  3. Start service

And each step has corresponding shellcommands, which are as follows:

  1. ps aux|grep blog-mxx.jar
  2. kill -9 10000
  3. nohup java -jar blog-mxx.jar --server.port=8800 > mxxblog.log 2>&1 &

So, here comes the question. If we need to do this every time we release a version, it will be very tiring... Is there a command that can directly execute the file shto complete the above steps?
Of course there is.

Automated service restart command

#!/bin/bash
#重启脚本
# 查找并杀死进程
pid=$(ps -ef | grep blog-mxx.jar | grep -v grep | awk '{print $2}')
if [ -n "$pid" ]; then
  kill $pid
fi

# 启动服务
nohup java -jar blog-mxx.jar --server.port=8800 > mxxblog.log 2>&1 &

For the above code, we put it directly shin a file, then pass it to the project and linuxexecute it directly in the system sh start.sh. (Note that the file saved by the above code is named start.sh)

Problems encountered

An error may be reported:
start.sh: line 11: syntax error: unexpected end of file

This is also easy to solve, it seems to be a file format issue. Solved like this:

  1. Use vimthe command to open start,shthe file, then look at the file format and enter the following command:
vim start.sh
:set ff

If the output is fileformat=doc, it proves to be a format problem. Enter the following command:

:set ff = unix		

Then execute the saved command:

:wq		

You can execute the query command:

:set ff

See if the format has changed fileformat=unix. If so, you can execute start.shthe file.

sh start.sh

That’s it for a long time. If you are still worried, you can check the input log:

tail -f mxxnlog.log

Guess you like

Origin blog.csdn.net/qq_34137397/article/details/132258437