git hook post-update 无法正常结束

2017-11-17 18:38:23 +08:00
 helloworld12

尝试着自动化部署,程序运行正常,写的脚本也正常运行了,但是 sourceTree 提交界面没法,关闭按钮无法关闭。。。只能点取消

originDir=`pwd`
# Check the remote git repository whether it is bare
IS_BARE=$(git rev-parse --is-bare-repository)
if [ -z "$IS_BARE" ]; then
        echo >&2 "fatal: post-receive: IS_NOT_BARE"
        exit 1
fi

# Check the deploy dir whether it exists
unset GIT_DIR
DEPLOY_DIR=/root/fishSer
if [ ! -d $DEPLOY_DIR ] ; then
	    echo >&2 "fatal: post-receive: DEPLOY_DIR_NOT_EXIST: \"$DEPLOY_DIR\""
    	exit 1
fi
cd $DEPLOY_DIR
echo "change to $DEPLOY_DIR"
#env -i git reset --hard

branch=$(git rev-parse --symbolic --abbrev-ref $1)
#GIT_WORK_TREE=$DEPLOY_DIR
git reset --hard

git checkout -f $branch
echo >&2 "branch: $branch"
git pull
echo >&2 "pull: $branch"

# Get the latest commit subject
SUBJECT=$(git log -1 --pretty=format:"%s")

# Deploy the HEAD sources to publish
IS_PULL=$(echo "$SUBJECT" | grep "\[deploy\]")
if [ -z "$IS_PULL" ]; then
	    echo >&2 "tips: post-receive: IS_NOT_PULL"
    	exit 1
fi
buildMain() {
    cd /root/fishSer/src/main
    go build -o main .
    mv main ~/nodes/$1/$1
    echo "build in ~/nodes/$1/$1"
}
killNode() {
    process=`ps -ef|grep $1|grep -v grep|grep -v post-update`
    echo "ser: " $process
    process=`echo $process|awk '{ print $2 }'`
    for i in $process
    do
            echo "Kill the $1 process [ $i ]"
            kill -9 $i
    done
}
buildMain $branch
echo "build $branch"
killNode $branch
cd ~/nodes/$branch/
echo "current in: " `pwd`
nohup ./$branch &

echo `ps -ef|grep $branch|grep -v grep|grep -v post-update`
echo "hello world"
cd $originDir
exit 0

git 提交输出的日志:

git -c diff.mnemonicprefix=false -c core.quotepath=false commit -q -F C:\Users\Administrator\AppData\Local\Temp\kiwi12r1.oip

git -c diff.mnemonicprefix=false -c core.quotepath=false push -v --tags --set-upstream origin node2:node2
Pushing to root@*****t/fishSerRepository
remote: change to /root/fishSer        
remote: HEAD is now at 1c8caf0 [deploy] 1024        
remote: Already on 'node2'        
remote: branch: node2        

remote: From /root/fishSerRepository        
remote:    1c8caf0..10a4540  node2      -> origin/node2        

remote: Updating 1c8caf0..10a4540        
remote: Fast-forward        
remote:  ReadMe | 2 +-        
remote:  1 file changed, 1 insertion(+), 1 deletion(-)        
remote: pull: node2        

remote: build in ~/nodes/node2/node2        
remote: build node2        

remote: ser:  root 4929 1 0 18:21 ? 00:00:00 ./node2        
remote: Kill the node2 process [ 4929 ]        
remote: current in:  /root/nodes/node2        
remote: root 5155 4991 0 18:26 ? 00:00:00 ./node2        
remote: hello world
2020 次点击
所在节点    Linux
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/407321

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX