su www
切換用戶(www)時:this account is currently not available
cat /etc/passwd | grep www # 查看是否爲 /sbin/nolgin
解決辦法:vim /etc/passwd
修改 /sbin/nolgin
爲 /bin/bash
php
ssh-keygen -t rsa -C "your_name"
git
公鑰位置:/home/www/.ssh/id_rsa.pub
在工蜂平臺新增SSH公鑰:工蜂平臺 -> 我的設置 -> SSH密鑰 -> 添加SSH密鑰, 複製粘貼 id_rsa.pub
中內容;github
須要使用 SSH 地址 git@github.com:someaccount/someproject.git
,若以前是使用 https 地址更新,則使用如下命令切換至 SSH 地址:git remote set-url origin git@github.com:someaccount/someproject.git
針對非www用戶已部署代碼,可修改其用戶權限至 www:chown -R www:www code_folder
web
<?php /* security */ $token = 'token12345'; $project = '/home/wwwroot/default/test/test'; //ip地址爲gitlab服務器請求地址 $access_ip = []; /* get user token and ip address */ $client_token = isset($_SERVER['HTTP_X_TOKEN']) ? $_SERVER['HTTP_X_TOKEN'] : ''; $client_ip = $_SERVER['REMOTE_ADDR']; //查詢服務器運行的php-fpm用戶和文件所屬權限是否一致 //print_r($_SERVER); //文件記錄日誌 /* create open log */ $fs = fopen($project . '/storage/webhook.log', 'a'); fwrite($fs, '===================================start====================================' . PHP_EOL); fwrite($fs, 'Request on [' . date("Y-m-d H:i:s") . '] from [' . $client_ip . ']' . PHP_EOL); /* test token */ if ($client_token !== $token) { echo "error 403"; fwrite($fs, "Invalid token [{$client_token}]" . PHP_EOL); exit(0); } /* test ip*/ // if ( ! in_array($client_ip, $access_ip)) // { // echo "error 503"; // fwrite($fs, "Invalid ip [{$client_ip}]".PHP_EOL); // exit(0); // } /* get json data */ $json = file_get_contents('php://input'); $data = json_decode($json, true); /* get branch */ $branch = $data["ref"]; $total_commits_count = $data["total_commits_count"]; fwrite($fs, '=======================================================================' . PHP_EOL); /* if you need get full json input */ //fwrite($fs, 'DATA: '.print_r($data, true).PHP_EOL); /* branch filter */ if ($branch === 'refs/heads/develop' && $total_commits_count > 0) { /* if master branch*/ fwrite($fs, 'BRANCH: ' . print_r($branch, true) . PHP_EOL); fwrite($fs, '=======================================================================' . PHP_EOL); /* then pull master */ // $result = shell_exec("cd {$project} && git pull 2>&1"); $result = shell_exec("cd {$project} && git pull 2>&1"); fwrite($fs, 'RESULT: ' . print_r($result, true) . PHP_EOL); fwrite($fs, '===================================end====================================' . PHP_EOL); $fs and fclose($fs); }
位置:項目 -> 設置 -> 高級設置 -> 網絡回調勾子shell