Get the App
SLTechnology News&Howtos  ›  Development  › 

How to start and stop SpringBoot jar programs by Linux

Shulou Source: shulou.com Published: 2022-06-01 00:57:00 09月12日 Update

This article mainly introduces the relevant knowledge of "how to start and stop SpringBoot jar programs in Linux". The editor shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how to start and stop SpringBoot jar programs in Linux" can help you solve the problem.

The specific code is as follows:

#! / bin/bashcd `cur $0`cur _ shell_dir= `pwd`cur _ shell_name= `basename ${bash_source} `# modify the jar package name here to jar_name= "xxxxxxxxxxxx.jar" jar_path=$cur_shell_dir/$jar_name#java_mem_opts= "- server-xms1024m-xmx1024m-xx:permsize=128m" java_mem_opts= "# spring_profiles_activ="-dspring.profiles.active=eureka2 "spring_profiles_activ="log_dir=$cur_shell_dir/logslog_path=$log_dir/$ {jar_name}. Logecho_help () {echo-e "syntax: sh $cur_shell_name start | stop"} if [- z $1] Then echo_help exit 1fiif [!-d "$log_dir"]; then mkdir "$log_dir" fiif [!-f "$log_path"]; then touch "$log_dir" fiif ["$1" = = "start"]; then# check server pids= `ps-- no-heading-c java-f-- width 1000 | grep $jar_name | awk'{print $2} '`if [- n "$pids"]; then echo-e "error: the $jar_name already started and the pid is ${pids}." Exit 1 fiecho "starting the $jar_name..." # start nohup java $java_mem_opts-jar $spring_profiles_activ $jar_path > > $log_path 2 > & 1 & count=0 while [$count-lt 1]; do sleep 1 count= `ps-no-heading-c java-f-width 1000 | grep "$jar_name" | awk'{print $2}'| wc-l`if [$count-gt 0] Then break fi done pids= `ps-- no-heading-c java-f-- width 1000 | grep "$jar_name" | awk'{print $2} '`echo "${jar_name} started and the pid is ${pids}." Echo "you can check the log file in ${log_path} for details." Elif ["$1" = = "stop"]; then pids= `ps-- no-heading-c java-f-- width 1000 | grep $jar_name | awk'{print $2} '`if [- z "$pids"]; then echo "error:the $jar_name does not started!" Exit 1 fiecho-e "stopping the $jar_name..." For pid in $pids; do kill $pid > / dev/null 2 > & 1 done count=0 while [$count-lt 1]; do sleep 1 count=1 for pid in $pids; do pid_exist= `ps-no-heading-p $pid`if [- n "$pid_exist"]; then count=0 break fi done done echo-e "${jar_name} stopped and the pid is ${pids}." else echo_help exit 1fi

The above code can be used simply by changing the jar package name

Start the jar package:

. / xxxx.sh start

Stop the jar package

. / xxxx.sh stop

This is the end of the introduction to "how Linux starts and stops SpringBoot jar programs". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Programs knowledge code industry different practical content just need practical practical articles methods more cases knowledge points articles information channels processes questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple vpn Redmi Linux Shulou Tech Info