4

I have modified a version of this github project https://github.com/lkwdwrd/git-deploy [I modified it as for some reason JSON wasnt being parsed on my server (Mediatemple Grid Server) & I also added custom logging] The script autodeploys github repos using git hooks.

The script was working fine for a while but recently stopped working.

I've isolated the problem to the git fetch command. This the exact code I'm using:

exec( 'git fetch ' . $this->_remote . ' ' . $this->_branch, $fetch_output, $fetch_return_var );

The $fetch_output array is blank and the $fetch_return_var is 255. So I believe that the 255 really means -1, which is an error with the git command.

However I am able to successfully execute this command when SSH'd into the server and running as the same user with the exact same string as is being build as the 1st argument of the exec() function.

So now I'm lost.

  • Is there an effective difference between running commands manually via SSH and using exec()?
  • Is there any way I can get the actual git fetch error that is being returned to exec()?
  • Could this be some kind of server configuration that has been changed by my host and that I should contact them for?

thanks in advance


UPDATE:

Thanks to @Matthias Huttar I changed my exec() to a proc_open() call that allowed me to see the output of STDERR [not sure why it was not logging thru exec() but I think it is because it was a subprocess of git fetch]. This output is:

error: cannot fork() for git-remote-https: Resource temporarily unavailable

So I think there is an issue with my server environment. However I'm still not certain.

1 Answer 1

2

if there is an error in you git fetch then the output will very likely not be written to stdout but to stderr. exec will only give you the output of stdout and ignore stderr.

exec( 'git fetch ' . $this->_remote . ' ' . $this->_branch.' 2>&1', $fetch_output, $fetch_return_var );

will very likely show your error. my suspicion is that the git process you invoke from php runs as a different user (e.g. you apache server's user) and therefore does nit have access to you ssh key (or username/password). If that is the case your error msg will be something with "permission denied". the solution would be o generate a new default ssh key for that user and grant this key access in github ("deploy key" is how github calls this)

Sign up to request clarification or add additional context in comments.

7 Comments

To confirm I ran exec('whoami') and the script is running as the same user as I log in with. & also the git repo doesn't use ssh but just https for the remote should shouldn't have errors with keys I don't think.
It seems that adding that to the end of the command still doesn't return anything from $fetch_output but changes $fetch_return_var to 254 (which is the old value minus 1?!)
How do you run that script? Is it run by Apache or shell executed? If you use normal https, is the repository completely public (no http author required)? Another option would be to use process open instead of exec that way you can fetch stdout and stderr separately. ( meaning that you will not need 2>&1 at the end
I believe the script is run by Apache. Github sends the payload to a url and the script parses that payload and does it's stuff. Yes the repo is public and anyone can clone with the http url. By process open do you mean proc_open()?
Yes I do mean proc_open. That should at least give you a clue on the error.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.