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

时间:2016-03-09 10:59:32

标签: 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脚本(即使退出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命令silent。但是,然后travis-ci几乎立即终止连接,命令将不会运行。我们还尝试添加&& exit 0,但服务器仍在等待响应。

1 个答案:

答案 0 :(得分:0)

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