Skip to content
......@@ -23,7 +23,7 @@ class SiteConfiguration extends Configuration {
function filename() {
$file = $this->context->getProperty('uri') . '.conf';
return $this->context->application->getConfig()->get('config_path') . '/' . $this->service->provider->name . '/' . $this->service->getType() . '/vhost.d/' . $file;
return $this->context->getProvision()->getConfig()->get('config_path') . '/' . $this->service->provider->name . '/' . $this->service->getType() . '/vhost.d/' . $file;
}
function process() {
......
<?php
/**
* @file
* The Provision HttpApacheService class.
*
* @see \Provision_Service_http_apache
*/
namespace Aegir\Provision\Service\Http;
use Aegir\Provision\Robo\ProvisionCollectionBuilder;
use Aegir\Provision\Service\Http\Apache\Configuration\PlatformConfiguration;
use Aegir\Provision\Service\Http\Apache\Configuration\ServerConfiguration;
use Aegir\Provision\Service\Http\Apache\Configuration\SiteConfiguration;
use Aegir\Provision\Service\HttpService;
use Aegir\Provision\ServiceSubscription;
use Robo\Result;
use Aegir\Provision\Service\Http\Php\PhpServer;
use Symfony\Component\Process\Process;
/**
* Class HttpPhpService
*
* @package Aegir\Provision\Service\Http
*/
class HttpPhpService extends HttpService
{
const SERVICE_TYPE = 'php';
const SERVICE_TYPE_NAME = 'PHP Server';
public function verifyServer()
{
$host = $this->getContext()->getProperty('remote_host');
$port = $this->getProperty('http_port');
$this->getProvision()->getLogger()->info('Running server at {host}:{port}', [
'host' => $host,
'port' => $port,
]);
//
$this->getContext()->getBuilder()->build(PhpServer::class, ['port' => $port]);
// $server = new PhpServer($port);
/** @var PhpServer $server */
$server = $this->getContext()->getBuilder()->task(PhpServer::class, ['port' => $port]);
$server->host($host);
$server->dir(__DIR__ . '/Php/servertest');
$server->background();
$server->run();
//
$pid = $server->getProcess()->getPid();
$this->getProvision()->getLogger()->info('Server started at {host}:{port} running as process {pid}', [
'host' => $host,
'port' => $port,
'pid' => $pid,
]);
}
public function verifySite()
{
}
public function verifySubscription(ServiceSubscription $subscription)
{
print_r($subscription->context->getProperty('root'));
$this->application->getBuilder()->taskServer($this->getProperty('http_port'))
->dir('.');;
}
}
<?php
namespace Aegir\Provision\Service\Http\Php;
use Robo\Common\ExecCommand;
use Robo\Common\ExecTrait;
class PhpServer extends \Robo\Task\Development\PhpServer {
/**
* @var int
*/
protected $port;
/**
* @var string
*/
protected $host = '127.0.0.1';
/**
* @var string
*/
protected $command = 'php -S %s:%d ';
/**
* @param int $port
*/
public function __construct($port)
{
$this->port = $port;
if (strtolower(PHP_OS) === 'linux') {
$this->command = 'exec php -S %s:%d ';
}
}
/**
* @param string $host
*
* @return $this
*/
public function host($host)
{
$this->host = $host;
return $this;
}
/**
* @param string $path
*
* @return $this
*/
public function dir($path)
{
$this->command .= "-t $path";
return $this;
}
/**
* {@inheritdoc}
*/
public function getCommand()
{
return sprintf($this->command, $this->host, $this->port);
}
public function run() {
$this->executeCommand($this->getCommand());
}
public function getProcess() {
return $this->process;
}
public function task() {
}
}
\ No newline at end of file
<h1><?php print "It Works!"; ?></h1>
<p>
<?php print "This page is being generated by PHP web server." ?>
</p>
......@@ -11,6 +11,7 @@ namespace Aegir\Provision\Service;
//require_once DRUSH_BASE_PATH . '/commands/core/rsync.core.inc';
use Aegir\Provision\Service;
use Aegir\Provision\ServiceInterface;
use Aegir\Provision\ServiceSubscription;
use Consolidation\AnnotatedCommand\CommandFileDiscovery;
......@@ -19,7 +20,7 @@ use Consolidation\AnnotatedCommand\CommandFileDiscovery;
*
* @package Aegir\Provision\Service
*/
class HttpService extends Service {
class HttpService extends Service implements ServiceInterface {
const SERVICE = 'http';
const SERVICE_NAME = 'Web Server';
......@@ -57,7 +58,7 @@ class HttpService extends Service {
*
* This is used to allow skipping of the service restart.
*/
function verifyProvider()
function verifyServer()
{
return [
'configuration' => $this->writeConfigurations(),
......@@ -67,14 +68,18 @@ class HttpService extends Service {
/**
* React to the `provision verify` command on Server contexts
*/
function verifySubscription(ServiceSubscription $serviceSubscription) {
$this->subscription = $serviceSubscription;
function verifySite() {
$this->subscription = $this->getContext()->getSubscription();
return [
'configuration' => $this->writeConfigurations($serviceSubscription),
'configuration' => $this->writeConfigurations($this->subscription),
'service' => $this->restartService(),
];
}
//
function verifyPlatform() {
}
//
// /**
// * Support the ability to cloak the database credentials using environment variables.
// */
......
<?php
namespace Aegir\Provision;
interface ServiceInterface
{
/**
* Triggered on `provision verify` command on Site contexts.
*/
public function verifySite();
/**
* Triggered on `provision verify` command on Platform contexts.
*/
public function verifyPlatform();
/**
* Triggered on `provision verify` command on Site contexts.
*/
public function verifyServer();
}
\ No newline at end of file
......@@ -9,6 +9,7 @@
namespace Aegir\Provision;
use Aegir\Provision\Common\ContextAwareTrait;
use Aegir\Provision\Common\ProvisionAwareTrait;
class ServiceSubscription {
......@@ -20,22 +21,23 @@ class ServiceSubscription {
public $properties = [];
use ProvisionAwareTrait;
use ContextAwareTrait;
function __construct(
Context $context,
$server,
$service_name
) {
$this->context = $context;
$this->server = Provision::getContext($server, $context->getProvision());
$this->setContext($context);
$this->setProvision($context->getProvision());
$this->server = $this->getProvision()->getContext($server);
$this->service = $this->server->getService($service_name);
$this->type = $this->server->getService($service_name)->type;
if (isset($context->config['service_subscriptions'][$service_name]['properties'])) {
$this->properties = $context->config['service_subscriptions'][$service_name]['properties'];
}
$this->setProvision($context->getProvision());
}
public function verify() {
......