Spring Boot应用程序不会在openshift中启动 [英] Spring boot application wont start in openshift
问题描述
我用DIY盒创建了openshift项目,并为数据库添加了postresql.现在我将源推送到云中,但是我遇到了像这里的家伙一样的错误(但他没有使用springboot):
I created openshift project with DIY cartridge, added postresql for DB.. now I pushed sources to cloud, but I'm getting error like the guy here (but he was not using springboot): I can't start tomcat 7 server on linux openshift - Failed to start end point associated with ProtocolHandler ["http-nio-12345"]
Failed to start end point associated with ProtocolHandler
很明显,如果我两次运行该应用程序,则会出现错误消息无法启动与ProtocolHandler相关联的终点".我尝试了rhc app-tidy,通过openshift界面重新启动了APP,我进行了更改,推送到云中,构建成功,但是消息再次出现.如何停止应用程序以便我可以正常运行?我执行重启后,应用程序没有停止吗?
It's obvious that if I run the app twice the error message 'Failed to start end point associated with ProtocolHandler' appears. I tried rhc app-tidy, restarted APP via openshift interface, i made change, pushed to cloud, build success, but the message appeared again. How to stop the app so that I can run it properly? Didn't the app being stopped after the restart I performed?
更新:我选择了正确的步骤吗? (使用DIY墨盒),您是否有一个简单的(可工作的)指南如何将这样的应用程序部署到openshift?我尝试了一些在网上找到的东西,但是都没有用:(
UPDATE: Have I chosen the right steps? (with DIY cartridge), do You have a simple (& working) guide how to deploy such an app to openshift? I tried few I found over the net, but none of them worked :(
推荐答案
以下是我使用DIY墨盒的步骤,希望对您有所帮助
Here is steps I follow using DIY cartridge, hope this would help
- 转到项目的主目录执行以下任务
-
创建Settings.xml并通过更新settings.xml来引用maven仓库,如下面的xml片段所示.并将文件添加到git repo
- Go to home directory of project perform following tasks
Create Settings.xml and refer maven repo by updating settings.xml as shown in following xml snippet below. And also add the file to git repo
<settings>
<localRepository>${OPENSHIFT_DATA_DIR}/m2/repository</localRepository>
</settings>
转到.openshift
目录并删除除action_hooks
Got to .openshift
directory and delete all the files except action_hooks
转到action_hooks
并执行以下任务
一世.删除README.md
ii.创建部署文件(请注意,文件扩展名在创建时不应为txt),并添加以下代码段
(它基本上会创建并下载并设置java8和maven
Go to action_hooks
and perform following task
i. Delete README.md
ii. Create deploy file (note the file extension while create should not be txt) and add following code snippet
(It basically creates and downloads and sets up java8 and maven
#!/bin/bash
set -x
if [ ! -d $OPENSHIFT_DATA_DIR/m2/repository ]
then
cd $OPENSHIFT_DATA_DIR
mkdir m2/repository
fi
if [ ! -d $OPENSHIFT_DATA_DIR/jdk1.8.0_51 ]
then
cd $OPENSHIFT_DATA_DIR
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u77-b03/jdk-8u77-linux-x64.tar.gz
tar xvf *.tar.gz
rm -f *.tar.gz
fi
if [ ! -d $OPENSHIFT_DATA_DIR/apache-maven-3.3.3 ]
then
cd $OPENSHIFT_DATA_DIR
wget http://mirror.fibergrid.in/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
tar xvf *.tar.gz
rm -f *.tar.gz
fi
cd $OPENSHIFT_REPO_DIR
export M2=$OPENSHIFT_DATA_DIR/apache-maven-3.3.3/bin
export MAVEN_OPTS="-Xms500m -Xmx500m"
export JAVA_HOME=$OPENSHIFT_DATA_DIR/jdk1.8.0_51
export PATH=$JAVA_HOME/bin:$M2:$PATH
mvn -s settings.xml clean install
iii.将部署文件添加到git
iv.使用以下代码段编辑start
文件.
iii. Add the deploy file to git
iv. Edit start
file with following snippet.
#!/bin/bash
source $OPENSHIFT_CARTRIDGE_SDK_BASH
set -x
export JAVA_HOME=$OPENSHIFT_DATA_DIR/jdk1.8.0_51
export PATH=$JAVA_HOME/bin:$PATH
cd $OPENSHIFT_REPO_DIR
nohup java –Xms500m –Xmx500m -jar target/*.jar --server.port=${OPENSHIFT_DIY_PORT} --server.address=${OPENSHIFT_DIY_IP} &
v.使用以下代码段编辑停止
v. Edit stop with following code snippet
#!/bin/bash
source $OPENSHIFT_CARTRIDGE_SDK_BASH
PID=$(ps -ef | grep java.*\.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
client_result "Application is already stopped"
else
kill $PID
fi
vi.使部署文件可执行(注意:这非常重要,这是常见错误,如果无法执行,则您的项目将无法启动)
vi. Make deploy file executable (Note: This is very important and its common mistake, if not executable your project will not start)
- 提交更改以及您的Maven
src
和pom.xml
您的应用程序应在提交完成后自动启动,
注意:这将是第一次,这将需要一些时间.需要下载Maven仓库. -
出于调试目的,最好在类路径(
src/main/resources
)中添加logback.xml
- Commit the changes along with your maven
src
andpom.xml
your application should automatically start once the commit is done,
Note: for first time it will take time as it needs to download maven repo. For debuging purpose, its better to add logback.xml in your class path(
src/main/resources
)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_FILE" value="${OPENSHIFT_LOG_DIR}/kp-apps.log" />
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="org.springframework.web" level="DEBUG" />
这篇关于Spring Boot应用程序不会在openshift中启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!