Merge "Follow-up I0b781c11 (2a55449): use User::getAutomaticGroups()."
[lhc/web/wiklou.git] / maintenance / hiphop / run-server
index 87695dd..1c4b51f 100755 (executable)
@@ -1,10 +1,75 @@
-#!/bin/bash
+#!/usr/bin/hphpi -f
+<?php
 
-sourceDir=`dirname "$0"`
+require( __DIR__ . '/../Maintenance.php' );
 
-"$sourceDir"/build/persistent/mediawiki-hphp \
-       --config="$sourceDir/server.conf" \
-       --mode=server \
-       --port=8080
+class RunHipHopServer extends Maintenance {
+       function __construct() {
+               parent::__construct();
+               $this->addOption( 'interpret', 'Run in interpreted mode' );
+       }
 
+       function execute() {
+               if ( $this->hasOption( 'interpret' ) ) {
+                       $this->runInterpreted();
+               } else {
+                       $this->runCompiled();
+               }
+       }
 
+       function runCompiled() {
+               global $wgHipHopBuildDirectory;
+               $thisDir = realpath( __DIR__ );
+               $IP = realpath( "$thisDir/../.." );
+               if ( strval( $wgHipHopBuildDirectory ) !== '' ) {
+                       $buildDir = $wgHipHopBuildDirectory;
+               } else {
+                       $buildDir = "$thisDir/build";
+               }
+
+               if ( file_exists( "$buildDir/source" ) ) {
+                       $sourceBase = "$buildDir/source";
+               } else {
+                       $sourceBase = realpath( "$IP/.." );
+               }
+
+               passthru( 
+                       'cd ' . wfEscapeShellArg( $sourceBase ) . " && " .
+                       'MW_INSTALL_PATH=' . wfEscapeShellArg( $IP ) . ' ' .
+                       wfEscapeShellArg( 
+                               "$buildDir/persistent/mediawiki-hphp",
+                               '-c', "$thisDir/server.conf",
+                               '-v', "Server.SourceRoot=$sourceBase",
+                               '-v', "Server.IncludeSearchPaths.0=$sourceBase",
+                               '-v', 'ServerVariables.MW_COMPILED=1',
+                               '--mode=server',
+                               '--port=8080'
+                       ),
+                       $ret
+               );
+               exit( $ret );
+       }
+
+       function runInterpreted() {
+               $thisDir = realpath( __DIR__ );
+               $IP = realpath( "$thisDir/../.." );
+               $sourceBase = realpath( "$IP/.." );
+
+               passthru(
+                       'cd ' . wfEscapeShellArg( $sourceBase ) . " && " .
+                       'MW_INSTALL_PATH=' . wfEscapeShellArg( $IP ) . ' ' .
+                       wfEscapeShellArg(
+                               'hphpi',
+                               '-c', "$thisDir/server.conf",
+                               '-v', "Server.SourceRoot=$sourceBase",
+                               '-v', "Server.IncludeSearchPaths.0=$sourceBase",
+                               '--mode=server',
+                               '--port=8080'
+                       ),
+                       $ret
+               );
+               exit( $ret );
+       }
+}
+$maintClass = 'RunHipHopServer';
+require_once( RUN_MAINTENANCE_IF_MAIN );