Linux—Microservice start and stop shell script writing template

run.sh

#!/bin/bash

if [ -s java.pid ]
then
  echo "重复启动,退出"
  exit 0
fi

jar_file=`ls *.jar | head -n 1`
echo $jar_file

java -Djava.security.egd=file:/dev/./urandom -jar $jar_file > test.log  2>&1 &
echo $! > java.pid

Run.sh with debug

#!/bin/bash

if [ -s java.pid ]
then
  echo "重复启动,退出"
  exit 0
fi

jar_file=`ls *.jar | head -n 1`
echo $jar_file

java -Djava.security.egd=file:/dev/./urandom -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000 -jar $jar_file > test.log  2>&1 &
echo $! > java.pid

Use -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000to specify the debug port as 8000

Specify run.sh of the configuration file

#!/bin/bash

if [ -s java.pid ]
then
  echo "重复启动,退出"
  exit 0
fi

jar_file=`ls *.jar | head -n 1`
echo $jar_file

java -Djava.security.egd=file:/dev/./urandom -jar $jar_file --spring.profiles.active=test > test.log  2>&1 &
echo $! > java.pid

If you need to specify a configuration file, you can --spring.profiles.active=testspecify it.

stop.sh

#!/bin/bash

if [ -s java.pid ]
then
  kill -9 `cat java.pid` && : > java.pid
fi

How to use

The run.shand stop.shand xxxx.jarbag put in the same directory

Published 118 original articles · Like 150 · Visits 40,000+

Guess you like

Origin blog.csdn.net/Andya_net/article/details/105490564