Index: branches/wmf/1.18wmf1/extensions/ExtensionDistributor/svn-invoker.conf.sample |
— | — | @@ -1,4 +1,4 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | $wgExtDistWorkingCopy = '/path/to/mw-working-copy'; |
5 | | - |
| 5 | +$wgExtDistLockFile = '/path/to/lock-file'; |
Index: branches/wmf/1.18wmf1/extensions/ExtensionDistributor/cron.php |
— | — | @@ -0,0 +1,52 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Script to be run from cron, to update the svn working copies (especially new extensions) |
| 6 | + */ |
| 7 | + |
| 8 | +if ( php_sapi_name() !== 'cli' ) { |
| 9 | + echo "This script can only be run from the command line\n"; |
| 10 | + exit( 1 ); |
| 11 | +} |
| 12 | + |
| 13 | +$wgExtDistWorkingCopy = false; |
| 14 | +$wgExtDistLockFile = false; |
| 15 | +$confFile = dirname( __FILE__ ) . '/svn-invoker.conf'; |
| 16 | +if ( !file_exists( $confFile ) ) { |
| 17 | + echo "Error: please create svn-invoker.conf based on svn-invoker.conf.sample\n"; |
| 18 | + exit( 1 ); |
| 19 | +} |
| 20 | +require( $confFile ); |
| 21 | + |
| 22 | +cronExecute(); |
| 23 | + |
| 24 | +function cronExecute() { |
| 25 | + global $wgExtDistLockFile; |
| 26 | + if ( $wgExtDistLockFile ) { |
| 27 | + $lockFile = fopen( $wgExtDistLockFile, 'r+' ); |
| 28 | + if ( !$lockFile ) { |
| 29 | + echo "Error opening lock file\n"; |
| 30 | + exit( 1 ); |
| 31 | + } |
| 32 | + if ( !flock( $lockFile, LOCK_EX | LOCK_NB ) ) { |
| 33 | + echo "Error obtaining lock\n"; |
| 34 | + exit( 1 ); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + // Update the files |
| 39 | + svnUpdate( "$wgExtDistWorkingCopy/trunk" ); |
| 40 | + for ( glob( "$wgExtDistWorkingCopy/branches/*", GLOB_ONLYDIR ) as $branch ) { |
| 41 | + svnUpdate( $branch ); |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +function svnUpdate( $path ) { |
| 46 | + $cmd = "svn up --non-interactive " . escapeshellarg( $path ); |
| 47 | + $retval = 1; |
| 48 | + system( $cmd, $retval ); |
| 49 | + if ( $retval ) { |
| 50 | + echo "Error executing command: $cmd\n"; |
| 51 | + exit( 1 ); |
| 52 | + } |
| 53 | +} |
Property changes on: branches/wmf/1.18wmf1/extensions/ExtensionDistributor/cron.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 54 | + native |
Index: branches/wmf/1.18wmf1/extensions/ExtensionDistributor/svn-invoker.php |
— | — | @@ -9,6 +9,8 @@ |
10 | 10 | exit( 1 ); |
11 | 11 | } |
12 | 12 | |
| 13 | +$wgExtDistWorkingCopy = false; |
| 14 | +$wgExtDistLockFile = false; |
13 | 15 | $confFile = dirname( __FILE__ ) . '/svn-invoker.conf'; |
14 | 16 | if ( !file_exists( $confFile ) ) { |
15 | 17 | echo "Error: please create svn-invoker.conf based on svn-invoker.conf.sample\n"; |
— | — | @@ -39,7 +41,7 @@ |
40 | 42 | } |
41 | 43 | |
42 | 44 | function svnExecute() { |
43 | | - global $wgExtDistWorkingCopy; |
| 45 | + global $wgExtDistWorkingCopy, $wgExtDistLockFile; |
44 | 46 | |
45 | 47 | $encCommand = ''; |
46 | 48 | $done = false; |
— | — | @@ -57,6 +59,30 @@ |
58 | 60 | return; |
59 | 61 | } |
60 | 62 | |
| 63 | + if ( $wgExtDistLockFile ) { |
| 64 | + $lockFile = fopen( $wgExtDistLockFile, 'r+' ); |
| 65 | + if ( !$lockFile ) { |
| 66 | + svnError( 'extdist-remote-error', "Unable to open lock file." ); |
| 67 | + return; |
| 68 | + } |
| 69 | + $timeout = 20; |
| 70 | + for ( $i = 0; $i < $timeout; $i++ ) { |
| 71 | + $wouldBlock = false; |
| 72 | + if ( flock( $lockFile, LOCK_EX | LOCK_NB ) ) { |
| 73 | + break; |
| 74 | + } |
| 75 | + if ( !$wouldBlock ) { |
| 76 | + svnError( 'extdist-remote-error', "Error attempting to obtain lock." ); |
| 77 | + return; |
| 78 | + } |
| 79 | + sleep( 1 ); |
| 80 | + } |
| 81 | + if ( $i == $timeout ) { |
| 82 | + svnError( 'extdist-remote-error', "Lock wait timeout." ); |
| 83 | + return; |
| 84 | + } |
| 85 | + } |
| 86 | + |
61 | 87 | $command = json_decode( $encCommand ); |
62 | 88 | if ( !isset( $command->version ) || !isset( $command->extension ) ) { |
63 | 89 | svnError( 'extdist-remote-error', "Missing version or extension parameter." ); |
Property changes on: branches/wmf/1.18wmf1/extensions/ExtensionDistributor |
___________________________________________________________________ |
Modified: svn:mergeinfo |
64 | 90 | Merged /trunk/extensions/ExtensionDistributor:r102482 |