2010-12-21 44 views
1

我創建了一個Subversion掛鉤,它執行各種操作,包括髮送電子郵件和更新服務器上的工作副本。當它從bash propt運行時,它可以很好地工作。在提交時通過TortoiseSVN或Netbeans運行時,會發送電子郵件等,但不會執行更新,也不會顯示任何錯誤。該文件是一個PHP文件,我使用反引號方法來運行bash命令。運行其他bash命令來編寫電子郵件,所以這不是問題。Subversion Hook不會在運行時自動運行'svn update',但會在bash提示符下運行

下面是應該運行更新並記錄結果的行。 $位置是從工作副本位置的數據庫中提取的。

$update_output = `/usr/local/bin/svn update /home/$location >> update.log`; 

由於

詹姆斯

編輯,更完整的腳本:

#!/usr/local/bin/php 
<? 
$REPOS = $argv[1]; 
$REV = $argv[2]; 

$output[] = `/usr/local/bin/svnlook dirs-changed -r $REV $REPOS`; 

foreach($output as $line) 
{ 
     preg_match("$([^/]+)$", $line, $array); 
     $projects[] = $array[0]; 
} 

$projects = array_unique($projects); 

$mysqli = new mysqli('localhost', 'svn_user', 'pringles', 'svn_maindb'); 

if ($mysqli->connect_error) { 
    die('Connect Error (' . $mysqli->connect_errno . ') ' 
      . $mysqli->connect_error); 
} 

foreach($projects as $project) 
{ 
     $query = "SELECT * FROM Project WHERE name = '$project' LIMIT 1"; 
     $result = $mysqli->query($query); 
     $row = $result->fetch_assoc(); 
     $proj_id = $row['id']; 
     $location = $row['location']; 
     if(!empty($location)) 
     { 
       $update_output = `/usr/local/bin/svn update /home/$location >> update.log`; 
     } 

     /* The below line only works when the script is run by hand */ 
     $test = `/usr/bin/lessecho test >> /home/svn/repo/hooks/update.log`; 


     /* Grab user from DB and call send_email for user */ 
} 

function send_email($REPOS, $REV, $programmer, $email) 
{ 
     $author = `/usr/local/bin/svnlook author -r $REV $REPOS`; 
     $message .= "Project Committed By $author 
     Comments: 
     "; 
     $message .= `/usr/local/bin/svnlook log -r $REV $REPOS`; 
     $message .= " 
     ===========List of Changes======== 

     U = Updated 
     A = Added 
     D = Deleted 

     "; 
     $message .= `/usr/local/bin/svnlook changed -r $REV $REPOS`; 

     /* Compose and Send Email */ 
} 
+1

什麼用戶SVN運行的?這是因爲權限嗎? – ircmaxell 2010-12-21 15:40:53

+0

我不確定,它可以運行svnlook,現在我已經用svn命令的完整路徑替換了svn。我怎麼能找出它正在運行的用戶? – jaz9090 2010-12-21 17:03:30

+0

如果您有權訪問命令行,請運行`ps aux | grep svnserve` ... – ircmaxell 2010-12-21 17:05:53

回答

1

根4231 0.0 0.0 61180 748 PTS/0 S + 17:09 0:00的grep的svnserve

這是因爲我作爲root運行它?如果它以root身份運行,那麼應該沒有權限問題?

1

我假定通過「SVN hook」,你的意思是由服務器執行的repository hook script。注意在SVN書的以下警告:

For security reasons, the Subversion repository executes hook programs with an empty environment—that is, no environment variables are set at all, not even $PATH (or %PATH%, under Windows). Because of this, many administrators are baffled when their hook program runs fine by hand, but doesn't work when run by Subversion. Be sure to explicitly set any necessary environment variables in your hook program and/or use absolute paths to programs.

在這種情況下,缺少了$ PATH意味着你必須調用SVN及其完整路徑,例如/usr/bin/svn

編輯:因爲svn update仍不完整路徑,甚至工作,我會嘗試將錯誤輸出是這樣的:

$update_output = `/usr/local/bin/svn update /home/$location 2>>/var/tmp/update-error.log`; 

EDIT2:爲svn update顯示錯誤輸出,這是一個許可問題。找出腳本運行的用戶(例如,通過在腳本中執行whoami > /var/tmp/whoami-output),並確保允許該用戶操縱正在嘗試更新的工作副本。

1

我同樣的問題,固定它如下:

#add apache user to group of target svn folder (project folder): 
    usermod -a -G [group_of_current_target_svn_folder] [apache_user, e.g. dhapache] 

    #change owner of target svn folder: 
    D=/home/pfu5er/public_html/dev2 
    chown -R [apache_user, e.g. dhapache] $D 
相關問題