Spring boot application wont start in openshift

不打扰是莪最后的温柔 提交于 2020-01-13 19:30:10

问题


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

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?

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 :(


回答1:


Here is steps I follow using DIY cartridge, hope this would help

  1. Go to home directory of project perform following tasks
  2. 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>
    
  3. Got to .openshift directory and delete all the files except action_hooks

  4. 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. 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. 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. Make deploy file executable (Note: This is very important and its common mistake, if not executable your project will not start)

  1. Commit the changes along with your maven src and pom.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.
  2. 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" />
    



来源:https://stackoverflow.com/questions/36251169/spring-boot-application-wont-start-in-openshift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!