1

I followed the standard tutorials out there in Spring website and couple of private articles.

  1. create a symbolic link of the jar to /etc/init.d/
  2. service myapp start

The service starts but it starts just like a normal app in foreground. Just like I ran

java -jar myapp.jar on the terminal

How do I make it run in the background just like mainstream linux services

This is my script

sudo chmod 500 myapp.jar
sudo /path/to/myapp.jar /etc/init.d/myapp

And I run the service as

sudo service myapp start

This is now running the app in foreground holds up the console , instead of running as service

madhairsilence
  • 3,787
  • 2
  • 35
  • 76
  • Related: http://stackoverflow.com/questions/21503883/spring-boot-application-as-a-service – g00glen00b Feb 13 '17 at 10:24
  • This is not a duplicate, the answer is, you must set embeddedLaunchScriptProperties > mode to "service" in spring-boot-maven-plugin plugin! This way your application will run as a service. – Thomas Decaux Sep 14 '17 at 12:20

1 Answers1

-1

Just add an & at the end of the java -jar yourApp.jar in your service script, this forks a process instead of using the process that calls the start.

java -jar yourApp.jar &
  • is it a clean solution. Coz.. even the official document does not say anything like this! – madhairsilence Feb 13 '17 at 10:01
  • It's a clean solution for running a process in the background, regardless of where it's used (init.d or elsewhere in your terminal/bash). If you want more advanced checks like preventing double starts, you might want to check out http://stackoverflow.com/questions/11203483/run-a-java-application-as-a-service-on-linux, as @Avinash pointed out... – Frederik Heremans Feb 13 '17 at 10:10
  • OK..But why has not these been mentioned in the doc. So is it expected for spring boot to run as foreground? – madhairsilence Feb 13 '17 at 10:28