ge1mina023
ge1mina023

Reputation: 175

Why would my spring boot application will shut down automatically?

update: I have followed spring boot deployment for Installation as an init.d Service (System V). I start my application successfully.But, after one day.My application closed again......Is there any ways to help me ?

I hava one spring boot application which names my.jar. I put it into my ubuntu server(20.04) and use the command of nohup java -jar my.jar &.In the first few hours, my application is in good condition.But,after one or two days,it will shut down automatically.

I have seen the log of my application which don't recorded any error and saved the last correct log before exiting

The current situation is my application is very simple and have only a small number of visits. According to my guess,it is seems that ubuntu kill my process for inactivity?

My scripts are as follow,

stop.sh:

#!/bin/bash
PID=$(ps -ef | grep centre-0.0.1-SNAPSHOT.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
            echo Application is already stopped
    else
                echo kill $PID
                    kill $PID
fi

run.sh:

#!/bin/bash
echo stop application
source stop.sh
echo start application
source start.sh

start.sh:

#!/bin/bash
nohup java -jar centre-0.0.1-SNAPSHOT.jar &

I need my application will run all the time. Is there any ways to resolve the issue?

Upvotes: 1

Views: 1754

Answers (2)

ge1mina023
ge1mina023

Reputation: 175

After I check the memory usage, so I realized that my spring boot have used a lot of memory abnormally.

I solved it in the following way: I updated my start.sh with the command of "nohup java -Xms100m -Xmx300m -jar ./target/centre-0.0.1-SNAPSHOT.jar &"

But, I did not figure out why did my spring boot application use a lot of memory? Is there anyone can explain this phenomenon?

Upvotes: 1

jmbourdaret
jmbourdaret

Reputation: 261

nohup is more suited for running processes that are expected to end after a while. For example running a lengthy batch script. As of why it is killed, there may be a number of reasons: memory leak, server security policy .... The server probably decided your program wasn't behaving correctly. Logs of the server, like dmesg or /var/log/ contents may have some clues about it.

What you said about your app receiving visits feels like it is more a service rather than a script.

You may want to daemonize your program . this will make your program tied to the server availability. Here is an explanation of the differences between nohup and daemons. Also check this link at baeldung for help on setting up the daemon

Upvotes: 1

Related Questions