开发者

Github hook bash script not pulling

I have a github account set up to my EC2 server with no issues. When i try to run a bash script to 'git pull' it wont do it. I will do a 'git status' and many other commands. Here is my sh file

cd /var/www/html/TDS/;
ls -la;
type gi开发者_运维问答t;

git status;
git remote -v;

git pull origin master;

echo "hello world";

All lines work except the git pull. I have tried git pull, git pull origin master, git fetch, git fetch origin master. I have ruled out all possibilities like permission issues and privileges.

This sh file is executed by hitting a PHP page, the PHP page looks like this

<?php
$output = shell_exec('/bin/sh /var/www/html/TDS/git.sh');
print_r("<pre>$output</pre>"); 
?> 

Very simple and it works minus the Pull request. Any help would be amazing, I'm so close to getting this to work.


For a git pull to work, the user running it must have write permissions to the git repo's index (under .git/). Make sure the user under which the script is run (Apache?) has those rights.


...does PHP (www-data) have permissions? Is it the owner of the file?


Is this an ssh URL to the origin repository? Do you have ssh-agent running when you do it manually? Have you provided ssh agent access to the shell script (hint, the answers are Yes, Yes, No. Probably.)

So we have determined it is ssh access that is the problem. You then have two choices: getting ssh-agent credentials into the php process and allowing the php script access to ssh credentials without requiring a password. Both are problematic one way or another.

To get assh-agent credentials into the php process, copy the $SSH_AUTH_SOCK environmental variable from a shell into your php/shell script SSH_AUTH_SOCK=/tmp/ssh-wScioBA10361/agent.10361 git pull. Then assuming the php script has sufficient privs to access that file, git pull will work. This is problematic because you need to ssh into the system to get the auth sock, change the program to use the new socket (or write a program to find the current socket), and leave everything running. Log out, reboot, etc and you will lose git pull functionality.

The other option is to create ssh credentials for the php/shell user who is running git pull. Find the home directory, create .ssh, and ssh-keygen new keys for that user. You can set up the private key to not have a password so that anyone who can access this file (security risk!!) can ssh using those credentials. Add the public key to the authorized keys of the account who has access to the git repo (gitolite would allow you to restrict what privileges that account might have).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜