linux - 通过 ssh 运行 bash 脚本以启动激活器后,Travis-ci 不会退出

标签 linux bash ssh travis-ci typesafe-activator

我们正尝试在构建成功后将 travis 持续部署到我们自己的服务器。

env:
  global:
    - ACTIVATOR_VERSION=1.3.7
    - ACTIVATOR_ZIP_FILE=typesafe-activator-${ACTIVATOR_VERSION}-minimal.zip
    - ACTIVATOR_ZIP_URL=http://downloads.typesafe.com/typesafe-activator/${ACTIVATOR_VERSION}/${ACTIVATOR_ZIP_FILE}
    - ACTIVATOR_BIN=${TRAVIS_BUILD_DIR}/activator-${ACTIVATOR_VERSION}-minimal/activator
    - "DEPLOY_USERNAME=#######"
    - "DEPLOY_PASSWORD=########"
    - "DEPLOY_HOST=########"

language: java

jdk:
  - oraclejdk8

addons:
  ssh_known_hosts:
    - ########
  apt:
    packages:
      - sshpass

install:
  - wget $ACTIVATOR_ZIP_URL
  - unzip -q $ACTIVATOR_ZIP_FILE

script:
  - $ACTIVATOR_BIN test

after_success:
  - sshpass -p $DEPLOY_PASSWORD ssh $DEPLOY_USERNAME@$DEPLOY_HOST -o stricthostkeychecking=no 'bash deploy.sh'

在我们的 travis 无误地完成后,它会在我们的服务器上运行一个 ssh 脚本来从我们的 git 中拉取,停止我们正在运行的激活器并启动一个新的激活器。 脚本:

#!/bin/bash
#Get the path of the local repository directory

set -o verbose

DIR="/home/ftpuser/eaglescience/"
TARGET="origin/develop"
SLEEP=1m

#echo "Go into directory " ${DIR}
cd ${DIR}
PID="`cat target/universal/stage/RUNNING_PID`"
#echo "Get the code from " ${TARGET}
git fetch --all
#echo "force checkout"
git checkout --force "${TARGET}"
#echo "Compiling activator"
activator clean stage
#echo "Running activator"
kill -15 ${PID}
target/universal/stage/bin/eaglescience -Dapplication.secret=############### &
#echo "Running..."
sleep ${SLEEP}
exit 0

这里的问题是 Travis-ci 在运行后不会退出 bash 脚本(即使是 exit 0)。这意味着 Travis-CI 将一直等待响应,直到它超时并导致我们的构建出错

一段时间后我们得到的响应如下:

[success] Total time: 33 s, completed Mar 9, 2016 11:19:20 AM
#echo "Running activator"
kill -15 ${PID}
target/universal/stage/bin/eaglescience -Dapplication.secret=########### &
#echo "Running..."
sleep ${SLEEP}
[warn] - application - system properties: application.secret is deprecated, use play.crypto.secret instead
[info] - play.api.Play - Application started (Prod)
[info] - play.core.server.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
exit 0
No output has been received in the last 10 minutes, this potentially indicates a stalled build or something wrong with the build itself.
The build has been terminated

我们尝试了很多不同的方法,我们尝试过静默运行 ssh bash 命令。但是 travis-ci 几乎立即终止了连接,命令将不会运行。我们还尝试添加 && exit 0 但服务器仍然在等待响应。

最佳答案

尝试使用 nohup 将 shell 文件输出到 /dev/null 2>&1 & 例如:nohup filename.sh >/dev/null 2> &1 &

关于linux - 通过 ssh 运行 bash 脚本以启动激活器后,Travis-ci 不会退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35889669/

相关文章:

bash - 在 bash 中只获取字符串的一部分的最简单方法

linux - bash + Linux + 如何忽略字符 "!"

linux - 如何创建一个不阻止写入器和读取器的 linux fifo "pipe"(或其他东西)?

linux - 我怎么知道我是否可以使用 FMA 指令集进行编译?

c# - 在linux中获取目录的可用空间

python - Python 中 Bash 的 exec $@ 相当于什么?

Linux命令'符号

bash - grep 从 shell 脚本内的串行端口输入 5 秒

linux - 用于从多个主机删除文件的 Shell 脚本

ssh - haproxy 在 ssh 连接 [TCP 前端/后端] 上发送 400 错误请求