dongxingdu9594 2013-03-06 10:09
浏览 108

Git POST webhook shell_exec

I have a script running the following shell_exec cmd in PHP.

echo shell_exec('cd /var/www/Library/Laravel/ ; git pull bitbucket master ; 2>&1');

This is being called by a webhook service and all I wanted to do is just cut out having to pull in this dev environment everytime we push.

However, I do not get any output errors or anything when this route is called. Can anyone suggest why this might be?

I get this echoing from the error_log ->

error: cannot open .git/FETCH_HEAD: Permission denied

I added the apache user to git and now I get the following error

Could not create directory '/var/www/.ssh'.
Host key verification failed.
fatal: The remote end hung up unexpectedly
  • 写回答

1条回答 默认 最新

  • duanmeng1858 2013-03-06 18:02
    关注

    I see a few problems here:

    1) your exec line "...; git pull bitbucket master ; 2>&1" should be "... git pull bitbucket master 2>&1" -- the extraneous semicolon is likely preventing you from seeing the standard error output.

    2) you found the ownership problem, so...

    3) I'm guessing you have an "ssh" based git URL. The first time you run SSH as a user it will try to validate host key (SSH id of the other side). The default behavior of SSH is to fail if the tool is not interactive and you have not yet accepted the key. Alternately, you'd see the same behavior if you've accepted the key but it has since changed. You would solve these two different problems differently.

    The "right" way to fix this would be to manually run the command (as that user with the appropriate HOME variable set) and manually accept the key so subsequent commands will "just work".

    Another possibility is to override SSH's default behavior -- see the documentation for the "StrictHostKeyChecking" SSH option. You can do some hacking to pass this on the command line or create a ~/.ssh/config file specifying the option. (NOTE: I recommend the first solution, not this one unless you understand the security implications.)

    And lastly, I suspect you'll also need to set up your SSH private key to allow you to pull as that user as well.

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序