5151 exit 1
5252fi
5353
54- # Include operation system function to for example detect Windows.
54+ # Include operation system function to for example detect Windows like isWindows .
5555source " ${SCRIPTS_DIR} /operatingSystemFunctions.sh"
5656
57- # Include functions to check or wait for the database to be ready
57+ # Include functions to check or wait for the database to be ready like isDatabaseQueryable.
5858source " ${SCRIPTS_DIR} /waitForNeo4jHttpFunctions.sh"
5959
6060# Check if Neo4j is stopped (not running) using a temporary NEO4J_HOME environment variable that points to the current installation
6161isDatabaseReady=$( isDatabaseQueryable)
62- if [[ ${isDatabaseReady} == " false" ] ]; then
62+ if [ " ${isDatabaseReady} " = " false" ]; then
6363 echo " stopNeo4j: ${neo4j_directory} already stopped"
6464 exit 0
6565else
7171 fi
7272fi
7373
74- # Check if Neo4j is still not running using a temporary NEO4J_HOME environment variable that points to the current installation
74+ # Check if Neo4j is still not running using a temporary NEO4J_HOME environment variable that points to the current installation
7575isDatabaseReady=$( isDatabaseQueryable)
76- if [[ ${isDatabaseReady} == " false" ] ]; then
76+ if [ " ${isDatabaseReady} " = " false" ]; then
7777 echo " stopNeo4j: Successfully stopped ${neo4j_directory} "
7878else
7979 if ! isWindows; then
8686if isWindows; then
8787 echo " stopNeo4j: Skipping detection of processes listening to port ${NEO4J_HTTP_PORT} on Windows"
8888else
89- port_listener_process_id=$( lsof -t -i:" ${NEO4J_HTTP_PORT} " -sTCP:LISTEN || true )
90- if [ -n " ${port_listener_process_id} " ]; then
91- echo " stopNeo4j: Terminating the following process that still listens to port ${NEO4J_HTTP_PORT} "
92- ps -p " ${port_listener_process_id} "
93- # Terminate the process that is listening to the Neo4j HTTP port
94- kill -9 " ${port_listener_process_id} "
89+ port_listener_process_ids=$( lsof -t -i:" ${NEO4J_HTTP_PORT} " -sTCP:LISTEN 2> /dev/null || true )
90+ if [ -n " ${port_listener_process_ids} " ]; then
91+ echo " stopNeo4j: Gracefully terminating process(es) listening to port ${NEO4J_HTTP_PORT} "
92+ ps -p " ${port_listener_process_ids} "
93+ # Try graceful shutdown first with SIGTERM
94+ kill -TERM " ${port_listener_process_ids} " 2> /dev/null || true
95+ sleep 20
96+ # Check if process(es) are still alive and force kill if necessary
97+ for pid in ${port_listener_process_ids} ; do
98+ if kill -0 " ${pid} " 2> /dev/null; then
99+ echo " stopNeo4j: Process ${pid} still alive after SIGTERM — sending SIGKILL"
100+ kill -KILL " ${pid} " 2> /dev/null || true
101+ fi
102+ done
95103 fi
96104fi
0 commit comments