1

I recently tried to start/stop a spring boot app (with an embedded tomcat) as a linux service from an init.d script

I eventually manage to do that, thanks to Spring Boot application as a Service answer, but during my trials and errors, I tried with start-stop-daemon, but ran into the following error when starting the service (I used the cron script to create my own) :

Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:62)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:54)
... 1 more
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat servlet container
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:165)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:293)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:141)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
at com.dsi.sale.indexer.Application.main(Application.java:22)
... 6 more
Caused by: java.lang.IllegalStateException: Tomcat connector in failed state
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:159)
... 16 more

I am not an expert on debian, so anyone understand why ? Is it related to start-stop-daemon ?

Here is the script :

#!/bin/bash
#
# chkconfig: 35 90 12
# description Runs with spring boot
#
PIDFILE=/var/run/indexer.pid
# Get function from functions library
. /lib/lsb/init-functions
# Start the service 
case "$1" in 
start)  log_daemon_msg "Starting indexer"
        start-stop-daemon --start --quiet --pidfile $PIDFILE --name  indexer --startas /path/to/indexer.sh
        log_end_msg $?
        ;;
stop)   log_daemon_msg "Stopping indexer"
        start-stop-daemon --stop --quiet --pidfile $PIDFILE --name indexer
        log_end_msg $?
        ;;
*)      log_action_msg "Usage: /etc/init.d/indexer  {start|stop|status|restart}"
    exit 2
    ;;
esac
exit 0

Thx.

edit: here is the command line that is executed by the sh called in the init.d :

#!/bin/sh
/usr/lib/jvm/java-8-oracle/bin/java -jar -Dspring.profiles.active=integration /home/user/solr/indexer.jar
Community
  • 1
  • 1
jlb
  • 358
  • 3
  • 15
  • The root cause for the exception must be deeper in the stacktrace, post it please. – Stefan Isele - prefabware.com Jul 01 '16 at 15:45
  • "Tomcat connector in failed state" is typically due to a port clash. Is anything else listening on the port that your Boot app is configured to use (8080 by default). – Andy Wilkinson Jul 01 '16 at 17:19
  • @ Stefan Isele : sorry, this is all that is printed. I'll try an see if nothing else is logged somewhere @AndyWilkinson : That is what I thought at first, but I did not change the starting port when using nohup. However, the default port (8080) for springboot is already used, but I start on the 8984 (as defined in the server.port properties on my app) – jlb Jul 03 '16 at 20:45
  • @AndyWilkinson : ok, it seems you were right, my application-${profile}.properties (located in the same directory than the jar file) seems to be ignored . This is this file that override the server.port (not overridden in the defautl properties packaged with the jar). Any hints ? – jlb Jul 05 '16 at 13:17

0 Answers0