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(); }
protected function executeAcquireLease(DrydockResource $resource, DrydockLease $lease) { // Because preallocated resources are manually created, we should verify // we have all the information we need. PhutilTypeSpec::checkMap($resource->getAttributesForTypeSpec(array('platform', 'host', 'port', 'credential', 'path')), array('platform' => 'string', 'host' => 'string', 'port' => 'string', 'credential' => 'string', 'path' => 'string')); $v_platform = $resource->getAttribute('platform'); $v_path = $resource->getAttribute('path'); // Similar to DrydockLocalHostBlueprint, we create a folder // on the remote host that the lease can use. $lease_id = $lease->getID(); // Can't use DIRECTORY_SEPERATOR here because that is relevant to // the platform we're currently running on, not the platform we are // remoting to. $separator = '/'; if ($v_platform === 'windows') { $separator = '\\'; } // Clean up the directory path a little. $base_path = rtrim($v_path, '/'); $base_path = rtrim($base_path, '\\'); $full_path = $base_path . $separator . $lease_id; $cmd = $lease->getInterface('command'); $cmd->execx('mkdir %s', $full_path); $lease->setAttribute('path', $full_path); }
public static function writeLog(DrydockResource $resource = null, DrydockLease $lease = null, $message) { $log = id(new DrydockLog())->setEpoch(time())->setMessage($message); if ($resource) { $log->setResourceID($resource->getID()); } if ($lease) { $log->setLeaseID($lease->getID()); } $log->save(); }