V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
helloworld12
V2EX  ›  Linux

git hook post-update 无法正常结束

  •  
  •   helloworld12 · 2017-11-17 18:38:23 +08:00 · 2009 次点击
    这是一个创建于 2344 天前的主题,其中的信息可能已经有所发展或是发生改变。

    尝试着自动化部署,程序运行正常,写的脚本也正常运行了,但是 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
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5252 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:22 · PVG 15:22 · LAX 00:22 · JFK 03:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.