Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get spring-boot to run forever on ubuntu?

I'm trying to run spring-boot on a vm and have nginx proxy all request towards it. I've got this working but when I run:

mvn spring-boot:run

And my ssh session ends, it will stop the spring boot instance. (as expected)

I've also tried adding the <executable> config and sym-linking the spring-boot jar to a service, like so:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
     <configuration>
           <executable>true</executable>
     </configuration>
</plugin>

Then symlink the .jar:

sudo ln -s /var/users-java/target/user-0.0.1-SNAPSHOT.jar /etc/init.d/user_service

Now when I run the service:

sudo /etc/init.d/user_service start

It will log out:

Started [26208]

But not run the actual server?! The 26208 PID won't show up in my processes either!

Any ideas? Is there an alternate way of running a spring boot app forever? Like the forever tool in node?

like image 748
James111 Avatar asked Jun 29 '16 00:06

James111


People also ask

What is the use of @service in spring boot?

It is used to mark the class as a service provider. So overall @Service annotation is used with classes that provide some business functionalities. Spring context will autodetect these classes when annotation-based configuration and classpath scanning is used. Add the spring-context dependency in your pom.

What is spring boot CommandLineRunner?

CommandLineRunner is a simple Spring Boot interface with a run method. Spring Boot will automatically call the run method of all beans implementing this interface after the application context has been loaded.


2 Answers

To run a command even after You logout you can use nohup command.

nohup stands for "no hangup." nohup is a POSIX command to ignore the hangup signal. The hangup signal is, by convention, the way a terminal warns dependent processes of logout.

https://en.wikipedia.org/wiki/Nohup

http://linux.101hacks.com/unix/nohup-command/

Your command will look somewhat like

nohup mvn spring-boot:run &
like image 55
A0__oN Avatar answered Sep 21 '22 16:09

A0__oN


If you are running you application in ubuntu, you can use nohup and & to run your process in background. It is simple and I hope it will solve your problem

nohup mvn spring-boot:run &

http://www.cyberciti.biz/tips/nohup-execute-commands-after-you-exit-from-a-shell-prompt.html

like image 30
sag Avatar answered Sep 17 '22 16:09

sag