After springboot starts, its process id needs to be recorded and written to a disk file.
The bash script can easily stop the program by PID.
A listener provided by springboot is very simple. Just add the listener instance to the SpringApplication before starting the springboot application.
Configure the write file for the process ID.
Special shell variables in Linux
The special variable
$! , is the pid of the last running background Process of the Shell.
So you can write the PID at the start of the application by using the following command.