Gabriel
Gabriel

Reputation: 962

Spring Boot Jar file start by terminal using nohup

Spring has this documentation for running an executable spring boot jar.

However, I ran this jar from terminal using the nohup linux command, and worked fine.

The question is: Using nohup or using init.d service, will have the same result for the application? Or using the init.d is the correct way always?

Upvotes: 1

Views: 5336

Answers (2)

dogoncouch
dogoncouch

Reputation: 249

nohup runs the command in a way that will be immune to hangups, which could cause problems. A lot of programs are designed to re-read their configuration files, restart, or do other things when they receive HUP signals (most services/daemons restart or re-read configs). Unless you specifically want to ignore HUP signals, using nohup isn't the best solution.

You can use & after the command in order to run it in the background, and if you want to avoid output to the terminal, you can send the output to /dev/null:

mycommand > /dev/null 2>&1 &

The 2>&1 will send stderr to stdout, so it goes to /dev/null.

Upvotes: 1

Elliott Frisch
Elliott Frisch

Reputation: 201537

They do different things. nohup runs a command, and ignores the HANGUP (HUP) signal. init.d is for running a command automatically at server start-up (and shutting commands down orderly on shutdown). If you want your spring boot application to run automatically after the system restarts, put it in init.d - if you want to manually start it after every reboot you can use nohup.

Upvotes: 3

Related Questions