Last active
August 29, 2015 14:27
-
-
Save forthxu/91a3f75db14d792890dc to your computer and use it in GitHub Desktop.
git hook部署
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // nohup /usr/local/php55/bin/php -S 0.0.0.0:82 -t /www/sync/ >> /www/sync/githook.log 2>&1 & | |
| // http://hostname:82/githook.php?token=xfs | |
| $valid_token = 'xfs'; | |
| $valid_ip = array('127.0.0.1'); | |
| $client_token = $_GET['token']; | |
| $client_ip = $_SERVER['REMOTE_ADDR']; | |
| $fs = fopen('./githook.log', 'a'); | |
| fwrite($fs, "\n".'Request on ['.date("Y-m-d H:i:s").'] from ['.$client_ip.']'.PHP_EOL); | |
| if ($client_token !== $valid_token) | |
| { | |
| echo "error 10001"; | |
| fwrite($fs, "Invalid token [{$client_token}]".PHP_EOL); | |
| exit(0); | |
| } | |
| if ( ! in_array($client_ip, $valid_ip) && 0) | |
| { | |
| echo "error 10002"; | |
| fwrite($fs, "Invalid ip [{$client_ip}]".PHP_EOL); | |
| exit(0); | |
| } | |
| $json = file_get_contents('php://input'); | |
| $data = json_decode($json, true); | |
| fwrite($fs, 'Data: '.print_r($data, true).PHP_EOL); | |
| fwrite($fs, '======================================================================='.PHP_EOL); | |
| $fs and fclose($fs); | |
| exec("cd /www/{$data['repository']['name']} && git pull;"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment