尝试重新启动与gitlab运行器的tomcat 8,创buildpid文件,logging为空,服务器未启动

我正在尝试部署后重新启动我的tomcat 8服务器。

build立:

gitlab-runner使用自己的用户(称为gitlab-runner)

tomcat使用自己的用户名为tomcat

  1. sudoers有一个条目,以便gitlab-runner可以运行脚本: gitlab-runner ALL=(tomcat) NOPASSWD: /home/tomcat/deploy.sh

  2. 部署脚本只是将文件复制到webapps目录中,closures并重新启动它:

cd /home/tomcat/bin sh catalina.sh stop -force ... sh catalina.sh start

当我手动运行脚本作为gitlab的运行者用户一切工作正常:

  1. sudo -u tomcat /home/tomcat/deploy.sh

但是,当从gitlab-ci-multi-runner开始工作(推送到gitlab存储库)时,会发生以下情况。 gitlab-runner基本上写了一个script.sh然后执行上面的命令。

  1. 通常当我启动tomcat我看到以下输出:closures:

Using CATALINA_BASE: /home/tomcat/ Using CATALINA_HOME: /home/tomcat/ Using CATALINA_TMPDIR: /home/tomcat/temp Using JRE_HOME: /usr Using CLASSPATH: /home/tomcat/bin/bootstrap.jar:/home/tomcat/bin/tomcat-juli.jar Using CATALINA_PID: /home/tomcat/bin/catalina.pid

对于启动: Using CATALINA_BASE: /home/tomcat/ Using CATALINA_HOME: /home/tomcat/ Using CATALINA_TMPDIR: /home/tomcat/temp Using JRE_HOME: /usr Using CLASSPATH: /home/tomcat/bin/bootstrap.jar:/home/tomcat/bin/tomcat-juli.jar Using CATALINA_PID: /home/tomcat/bin/catalina.pid Existing PID file found during start. Removing/clearing stale PID file. Tomcat started. Using CATALINA_BASE: /home/tomcat/ Using CATALINA_HOME: /home/tomcat/ Using CATALINA_TMPDIR: /home/tomcat/temp Using JRE_HOME: /usr Using CLASSPATH: /home/tomcat/bin/bootstrap.jar:/home/tomcat/bin/tomcat-juli.jar Using CATALINA_PID: /home/tomcat/bin/catalina.pid Existing PID file found during start. Removing/clearing stale PID file. Tomcat started.

当我用gitlab-runner启动它时,没有closures的输出,但服务器closures。 这实际上是工作。

对于只有Tomcat started. 显示。

  1. 一个pid文件是用pid创build的,但是这个进程不存在。

  2. 日志文件被创build,但是它们是空的。

如果我以debugging模式启动服务器: sh catalina.sh jpda start文件log / catalina.out只需要包含一行: tomcat Listening for transport dt_socket at address: 8080


我的想法是,环境是不同的,所以我检查了env cmd。 一切都是平等的,除了TERM=unknown时候,由gitlab运行程序启动。

你有什么线索可能发生在后台或只是我可以testing的东西吗?

gitlab-runner是开源的,启动构build脚本的脚本是这样的: https ://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/executors/shell/executor_shell.go#L36

我终于想出了一个可行的解决scheme。

对于不显示环境variables的问题,我参考: https ://bz.apache.org/bugzilla/show_bug.cgi ? id = 37848 gitlab没有tty,所以没有输出显示。

引发故障的原因如下:寻找gitlab-runner的源代码,你可以find这个: https ://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/executors /shell/executor_shell.go#L84

基本上只要gitlab-runner完成,就会杀死所有剩余的进程。 这意味着在我的情况下,服务器实际上运行了很短的时间,然后进程被杀死了。 这就是为什么我得到空的日志文件。

我通过简单地编写一个init脚本来启动和closurestomcat来解决这个问题。 tomcat现在有自己的用户(和组)。 现在,tomcat进程树由/ sbin / init启动。 现在gitlab运行者不知道这个过程了,或不能杀死它。 无论哪种方式,在跑步者停止之后,tomcat继续运行。

简单地否认你的过程将做,例如tomcat(写在你的.gitlab-ci.yml ):

 deploy_to_tomcat: stage: deploy script: - sudo /opt/apache-tomcat-7.0.77-dbservice/bin/startup.sh & - disown