Spring Boot version : 2.2.4.RELEASE OS (uname -a) : Linux hostname 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

On a Linux server, there is an init.d "service_name" service implemented as a Spring Boot "executable". The "service service_name status" Linux command used in supervision returned sometimes "Running", but the service was inactive. So I run the following in a bash shell to reproduce this bug :

for i in {1..10000}
do
    service service_name status
    echo $?
done

The output contains an error ::

Running [15344]
0

I think I found the root cause of this bug. The Linux command "service service_name status" (with the name of one Linux init.d service implemented as a Spring Boot "executable") uses a process number (PID) to know if the service is active. It is problematic, because when the service is idle (and the PID of its last run was saved), a new unrelated Linux process might be assigned this PID. And the command will then indicate that this service is active, when it is not.

The problematic code is in this file :: https://github.com/spring-projects/spring-boot/blob/v2.2.4.RELEASE/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script

This file contains ::

isRunning() {
  ps -p "$1" &> /dev/null
}
status() {
  working_dir=$(dirname "$jarfile")
  pushd "$working_dir" > /dev/null
  [[ -f "$pid_file" ]] || { echoRed "Not running"; return 3; }
  pid=$(cat "$pid_file")
  isRunning "$pid" || { echoRed "Not running (process ${pid} not found)"; return 1; }
  echoGreen "Running [$pid]"
  return 0
}

Comment From: wilkinsona

I don't think there's anything meaningful that we can do about this in our launch script. If it's causing problems, using daemontools instead may produce better results.