我最近尝试从init.d脚本启动/停止一个Spring启动应用程序(带有嵌入式tomcat)作为linux服务
我最终设法做到这一点,感谢Spring Boot application as a Service回答,但在我的试验和错误期间,我尝试使用start-stop-daemon,但在启动服务时遇到了以下错误(我使用了cron脚本来创建我自己的):
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
我不是debian的专家,所以任何人都明白为什么?它与start-stop-daemon有关吗?
这是脚本:
#!/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:这是由init.d:
中调用的sh执行的命令行#!/bin/sh
/usr/lib/jvm/java-8-oracle/bin/java -jar -Dspring.profiles.active=integration /home/user/solr/indexer.jar