GitLab post-receive hook不会触发

道歉,如果这不是正确的堆栈交换。

我有一个GitLab安装。 它被安装在只有几天的gitolite安装的顶部,我认为这个非标准的设置是我的问题的根源,但我不能把它钉住。

问题很简单:后接收钩不会被解雇。 这可以防止在GitLab中出现“项目活动”。 问题如下所示:

$ git push #... error: cannot run hooks/post-receive: No such file or directory 

钩子存在

后接收钩子/符号链接存在并且是可执行的:

 -rwxr-xr-x 1 git git 470 Oct 3 2012 .gitolite/hooks/common/post-receive lrwxrwxrwx 1 git git 45 Oct 3 2012 repositories/project.git/hooks/post-receive -> /home/git/.gitolite/hooks/common/post-receive 

它是可执行的由GitLab

gitlab用户可以执行这个脚本(我已经删除了/dev/nullredirect,并在空白input中input'OK'作为输出):

 sudo su - gitlab -c /home/git/.gitolite/hooks/common/post-receive OK 

GitLab可以find它

GitLab正在寻找钩子在正确的位置:

 $ grep hooks /srv/gitlab/gitlab/config/gitlab.yml hooks_path: /home/git/.gitolite/hooks/ 

 $ bundle exec rake gitlab:app:status RAILS_ENV=production # ... /home/git/.gitolite/hooks/common/post-receive exists? ............YES 

GitLab作为正确的用户运行

GitLab软件由gitlab用户运行:

 $ ps U gitlab PID TTY STAT TIME COMMAND 3650 ? Sl 0:59 unicorn_rails master -c /srv/gitlab/gitlab/config/unicorn.rb -E production -D 3671 ? Sl 0:43 unicorn_rails worker[0] -c /srv/gitlab/gitlab/config/unicorn.rb -E production -D 3674 ? Sl 0:42 unicorn_rails worker[1] -c /srv/gitlab/gitlab/config/unicorn.rb -E production -D # ... 

环境

钩子中的env -i行通常被引用为一个问题。 我认为这会发生这个问题之后,但是为了完整性,发现redis-cli是可以的:

 $ env -i redis-cli redis> 

我已经用完了这个debugging的想法。 有人有什么build议吗?

好吧,算出这一个。 这种情况很可能会适用于其他人,所以我已经logging下来。

我们的基础设施具有所有外部SSH连接登陆到特定的机器上1 。 这不是运行gitlab的机器。 这并不明显,因为gitolite + gitlab尽pipe如此。 我们的家乡是NFS挂载,并且SSH机器和gitlab机器都将gitolite文件视为“local”。 这个“分布式”gitolite + gitlab的一个问题是post-receive钩子试图调用redis-cli ,这是一个在运行钩子的机器上不存在的二进制文件。

为了解决这个问题,我在接受SSH连接的机器上安装了redis-server软件包(不幸的是, redis-cli二进制文件似乎没有单独提供)。 然后,我将/home/git/.gitolite/hooks/common/post-receive的redis行修改为以下内容:

 redis-cli -h hostname rpush "resque:queue:post_receive" "{\"class\":\"PostReceive\",\"args\":[\"$reponame\",\"$oldrev\",\"$newrev\",\"$ref\",\"$GL_USER\"]}" > /dev/null 2>&1 

-h hostname开关是唯一的补充。 这会使redis rpush命令在正确的机器上发送到redis。

由于钩子脚本中的> /dev/null 2>&1redirect,遗漏的二进制错误没有出现。 虽然我在debugging过程中将其删除,但在尝试通过git push触发挂钩之前,我必须先将其还原,否则会回显错误。

我关于我的稍微不标准的gitlab安装的假设certificate是不正确的。 无论如何,这个问题都会发生。 这是由于networking的怪癖。 无论如何,我希望这将是有用的人。

  1. 在git的情况下,即使在本地networking中也使用外部URL,因此无论networking环境如何,项目URL都是一致的。

我有同样的问题,但原因是不同的。

我的redis安装位于/usr/local/bin 。 Git用户在它的PATH ,但没有效果。

我不得不在脚本中明确地从/usr/local/bin/redis-cli开始redis:

 env -i /usr/local/bin/redis-cli rpush "resque:queue:post_receive" "{\"class\":\"PostReceive\",\"args\":[\"$reponame\",\"$oldrev\",\"$newrev\",\"$ref\",\"$GL_USER\"]}" > /dev/null 2>&1 

它解决了我的问题后接收钩不开火。

我希望这对别人也有帮助。