public function executeAcquireLease(DrydockResource $resource, DrydockLease $lease) { $key = Filesystem::readRandomCharacters(12); $ports = $resource->getAttribute('ports', array()); for ($ii = 2000;; $ii++) { if (empty($ports[$ii])) { $ports[$ii] = $lease->getID(); $port = $ii; break; } } $resource->setAttribute('ports', $ports); $resource->save(); $host = $resource->getAttribute('host'); $lease->setAttribute('port', $port); $lease->setAttribute('key', $key); $lease->save(); $config = <<<EOCONFIG Listen *:{$port} <VirtualHost *:{$port}> DocumentRoot /opt/drydock/webroot/{$key}/ ServerName {$host} </VirtualHost> EOCONFIG; $cmd = $this->getInterface($resource, $lease, 'command'); $cmd->execx(<<<EOSETUP sudo mkdir -p %s && sudo sh -c %s && sudo /etc/init.d/httpd restart EOSETUP , "/opt/drydock/webroot/{$key}/", csprintf('echo %s > %s', $config, "/etc/httpd/conf.d/drydock-{$key}.conf")); $lease->setAttribute('uri', "http://{$host}:{$port}/"); $lease->save(); }
public function getPendingLease() { if (!$this->lease) { $lease = new DrydockLease(); $lease->setStatus(DrydockLeaseStatus::STATUS_PENDING); $lease->save(); $this->lease = $lease; } return $lease; }