/**
  * Run the operation
  */
 public function execute()
 {
     $this->status(Phase::INSTALL_PACKAGES());
     $this->enterRoot();
     $this->payload = (array) $this->payload;
     // Prep the packager, pick the base command
     switch ($this->packager_type) {
         default:
         case PackagerType::YUM():
             $this->waitForYum(self::CMD_TIMEOUT);
             $cmd_base = 'yum -y install ';
             $allowed_errors = ['Existing lock '];
             break;
         case PackagerType::APT():
             $cmd_base = 'apt-get -y install ';
             $allowed_errors = ['Extracting templates from packages:'];
             if (!$this->sendCommand("apt-get -y update", self::CMD_TIMEOUT)) {
                 $this->exitRoot();
                 throw new ApplicationException("Update failed");
             }
             break;
     }
     // Install all packages
     $package = implode(' ', $this->payload);
     if (!$this->sendCommand($cmd_base . $package, self::CMD_TIMEOUT, $allowed_errors)) {
         $this->exitRoot();
         throw new ApplicationException("Installation of system packages failed");
     }
     $this->exitRoot();
 }
 /**
  * Get the appropriate repository cloner
  *
  * @return RepositoryCloner
  */
 protected function getCloner()
 {
     switch ($this->payload->getRepositoryType()) {
         default:
             $this->status(Phase::ERROR(), 0, 0, "Unknown repository type: " . $this->payload->getRepositoryType());
             return null;
         case RepositoryType::GIT():
             return new GitCloner();
         case RepositoryType::SVN():
             return new SvnCloner();
     }
 }
Beispiel #3
0
 /**
  * Run the operation
  */
 public function execute()
 {
     if (!is_array($this->payload)) {
         $this->payload = explode("\n", $this->payload);
     }
     $this->status(Phase::SCRIPT());
     if ($this->run_as_root) {
         $this->enterRoot();
     }
     foreach ($this->payload as $command) {
         $this->output($this->shell->sendSmartCommand($command, false, $this->timeout, true));
     }
     if ($this->run_as_root) {
         $this->exitRoot();
     }
 }
 /**
  * Run the operation
  */
 public function execute()
 {
     $this->status(Phase::RUN_SERVICES());
     $this->enterRoot();
     $services = (array) $this->payload;
     foreach ($services as $service) {
         $service = trim($service);
         if (!$service) {
             continue;
         }
         // Break out the service type from the service name
         // eg: "upstart/networking" or "systemd/apache2"
         $parts = explode('/', $service, 2);
         if (count($parts) == 2) {
             $manager = $parts[0];
             $service_name = $parts[1];
         } else {
             $manager = self::DEFAULT_SERVICE_TYPE;
             $service_name = $parts[0];
         }
         $service_type = ServiceType::memberByKey(strtoupper($manager));
         $allowed_errors = ['start: Job is already running: '];
         switch ($service_type) {
             default:
                 throw new UnexpectedValueException("Unknown service type: " . $manager);
             case ServiceType::SYSTEMD():
                 $cmd = 'systemctl start ' . $service_name . '.service';
                 break;
             case ServiceType::UPSTART():
                 $cmd = 'start ' . $service_name;
                 $allowed_errors[] = 'start: Job is already running: ';
                 break;
             case ServiceType::SYSVINIT():
                 $cmd = 'service ' . $service_name . ' start';
                 break;
         }
         if (!$this->sendCommand($cmd, 15, $allowed_errors)) {
             $this->exitRoot();
             throw new ApplicationException("Failed to start service [" . $service_name . "]");
         }
     }
     $this->exitRoot();
 }
Beispiel #5
0
 /**
  * Run the operation
  */
 public function execute()
 {
     $this->status(Phase::ENVIRONMENT());
     $this->shell_type = $this->shell->getShellType();
     $this->logger->debug("Remote shell is identifying as " . $this->shell_type->value());
     foreach ($this->variables as $key => $value) {
         switch ($this->shell_type) {
             // Bourne-shell compatibles
             default:
                 $cmd = 'export ' . $key . '="' . $value . '"';
                 break;
                 // C-shell compatibles
             // C-shell compatibles
             case ShellType::CSH():
             case ShellType::TCSH():
                 $cmd = 'set ' . $key . '="' . $value . '"';
         }
         $this->output($this->shell->sendSmartCommand($cmd, false));
     }
 }
 /**
  * Run the operation
  */
 public function execute()
 {
     $this->enterRoot();
     $this->status(Phase::UPDATE_PACKAGES());
     switch ($this->packager_type) {
         default:
         case PackagerType::YUM():
             $this->waitForYum(self::CMD_TIMEOUT);
             $cmds = ['yum -y update'];
             $allowed_errors = ['Existing lock '];
             break;
         case PackagerType::APT():
             $cmds = ['apt-get -y update', 'apt-get -y upgrade'];
             $allowed_errors = ['Extracting templates from packages:'];
             break;
     }
     foreach ($cmds as $cmd) {
         if (!$this->sendCommand($cmd, self::CMD_TIMEOUT, $allowed_errors)) {
             $this->exitRoot();
             throw new ApplicationException("System packager failed during update");
         }
     }
     $this->exitRoot();
 }
Beispiel #7
0
 /**
  * Report status to the log and callback
  *
  * From an operation, the Phase should only ever be Phase::SUB_OPERATION() or Phase::ERROR().
  *
  * @param Phase  $phase
  * @param int    $step
  * @param int    $total
  * @param string $message
  */
 protected function status(Phase $phase, $step = 0, $total = 0, $message = '')
 {
     $this->logger->debug('[' . $phase->value() . '] ' . $message);
     if ($this->callback) {
         $closure = $this->callback;
         $closure($phase, $step, $total, $message);
     }
 }
Beispiel #8
0
 /**
  * Report status to the log and callback
  *
  * @param Phase  $phase
  * @param int    $step
  * @param int    $total
  * @param string $message
  */
 protected function status(Phase $phase, $step, $total, $message)
 {
     $this->logger->info('[' . $phase->value() . '] ' . $message);
     if ($this->status_callback) {
         $closure = $this->status_callback;
         $closure($phase, $step, $total, $message);
     }
 }