代码拉取完成,页面将自动刷新
#!/bin/bash
INSTALL_DIR=${INSTALL_DIR}
REPO=${REPO}
REPO_URL=${REPO_URL}
# wait_for_startup friendly_name url timeout_s
function wait_for_startup() {
local server_name="$1"
local server_url="$2"
local timeout_s="$3"
local now_s=`date '+%s'`
local stop_s=$(( $now_s + $timeout_s ))
local status
echo -n "Connecting to $server_name ($server_url)"
while [ $now_s -le $stop_s ]; do
echo -n .
status=`curl -o /dev/null -s -w %{http_code} $server_url`
if [ $status -eq 200 ]; then
echo "OK"
return 0
fi
sleep 2
now_s=`date '+%s'`
done
echo "The operation timed out when attempting to connect to $server_url" >&2
return 1
}
PID=`ps aux | grep "$REPO" | grep -v 'grep' | awk '{print $2}'`
if [ -n "$PID" ]; then
kill -9 $PID
fi
rm -rf $INSTALL_DIR/$REPO
git clone $REPO_URL/$REPO $INSTALL_DIR/$REPO || exit 1
# Jenkins will kill process with current BUILD_ID
# http://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build
# http://excid3.com/blog/running-background-daemon-scripts-with-jenkins
OLD_BUILD_ID=$BUILD_ID
BUILD_ID=dontKillMe
gitbook serve --port 8001 $INSTALL_DIR/$REPO &
BUILD_ID=$OLD_BUILD_ID
wait_for_startup $REPO http://localhost:8001 30
if [ $? -eq 0 ]; then
echo "Deploy OK!"
exit 0
else
echo "Deploy Failed!"
exit 1
fi
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。