/** * @throws \Exception */ public function run() { if (!$this->command instanceof ProvisionCommand) { throw new \Exception("The ServiceRestart task can only be run by the Provision command."); } $this->output->writeInfo("Restarting services"); $this->output->writeDebug("Stopping monit"); Util::process($this->output, "monit quit"); // wait until monit quits while (file_exists('/var/run/monit.pid')) { usleep(500000); } $services = ServiceManager::getServices(); $this->output->writeDebug("Stopping services"); foreach ($services as $service) { Util::process($this->output, "monit stop {$service}"); } $this->output->writeDebug("Starting services"); foreach ($services as $service) { Util::process($this->output, "monit start {$service}"); } $this->output->writeDebug("Starting monit"); Util::process($this->output, "monit"); }
/** * Stops php-fpm * * @param $build * @throws \Exception */ protected function stopFpm($build) { $this->output->writeInfo("Stopping php-fpm service"); $proc = Util::process($this->output, "monit stop php-{$build}-fpm"); if ($proc->isSuccessful()) { // wait until monit stops the service while (file_exists("/opt/phpbrew/php/{$build}/var/run/php-fpm.pid")) { usleep(500000); } } }
/** * @throws \Exception */ public function run() { if (!$this->command instanceof ProvisionCommand) { throw new \Exception("The ProjectsInit task can only be run by the Provision command."); } $this->output->writeInfo("Finding projects"); $projects_catalog = Projects::get(); $projects = ['skip' => [], 'check' => [], 'modify' => [], 'create' => [], 'delete' => []]; $publicdb = '/etc/dashbrew/public.fndb'; $proc = Util::process($this->output, "updatedb -U /vagrant/public -o {$publicdb}"); if (!$proc->isSuccessful()) { throw new \Exception("Failed indexing '/vagrant/public' directory"); } $files = []; $proc = Util::process($this->output, "locate -d {$publicdb} -i -b '*.dashbrew'"); if ($proc->isSuccessful()) { $files = explode("\n", trim($proc->getOutput(), "\n")); } $yaml = Util::getYamlParser(); foreach ($files as $file_path) { if (!is_file($file_path)) { continue; } try { $file_projects = $yaml->parse(file_get_contents($file_path)); } catch (\Symfony\Component\Yaml\Exception\ParseException $e) { $this->output->writeError("Failed parsing '{$file_path}': " . $e->getMessage()); continue; } foreach ($file_projects as $id => $project) { $project['_path'] = $file_path; if (isset($projects_catalog[$id])) { $project['_created'] = $projects_catalog[$id]['_created']; $project['_modified'] = $projects_catalog[$id]['_modified']; if ($project == $projects_catalog[$id]) { if ($this->__projectNeedsCheck($id, $project)) { $projects['check'][$id] = $project; } else { $projects['skip'][$id] = $project; } } else { $project['_modified'] = time(); $projects['modify'][$id] = $project; } } else { # Ignore duplicates if (isset($projects['create'][$id])) { $this->output->writeError("Unable to proccess project '{$id}' at '{$project['_path']}', " . "another project with the same name is already exist at '{$projects['create'][$id]['_path']}'."); continue; } $project['_created'] = time(); $project['_modified'] = time(); $projects['create'][$id] = $project; } if (isset($projects_catalog[$id])) { unset($projects_catalog[$id]); } } } # Prevent project duplicates foreach ($projects['create'] as $id => $project) { foreach (['skip', 'check', 'modify'] as $action) { if (isset($projects[$action][$id])) { $this->output->writeError("Unable to proccess project '{$id}' at '{$project['_path']}', " . "another project with the same name is already exist at '{$projects[$action][$id]['_path']}'."); unset($projects['create'][$id]); } } } # Projects that are no longer exist needs to be deleted foreach ($projects_catalog as $id => $project) { $projects['delete'][$id] = $project; } Registry::set('projects', $projects); $projects_total = count($projects['skip']) + count($projects['check']) + count($projects['modify']) + count($projects['create']) + count($projects['delete']); if ($projects_total > count($projects['skip'])) { $this->output->writeInfo("Found " . $projects_total . " project(s)" . (count($projects['skip']) > 0 ? "\n |--> " . count($projects['skip']) . " will be skipped" : "") . (count($projects['check']) > 0 ? "\n |--> " . count($projects['check']) . " don't have changes but needs to be checked" : "") . (count($projects['create']) > 0 ? "\n |--> " . count($projects['create']) . " will be created" : "") . (count($projects['modify']) > 0 ? "\n |--> " . count($projects['modify']) . " will be modified" : "") . (count($projects['delete']) > 0 ? "\n |--> " . count($projects['delete']) . " will be deleted" : "")); } else { $this->output->writeDebug("Found {$projects_total} project(s)"); } }
/** * Manages nodjs modules via npm */ protected function manageNpmPackages() { $packages_config = Config::get('npm::packages'); if (empty($packages_config)) { return; } $this->output->writeInfo("Checking nodejs modules"); $packages = ['install' => [], 'remove' => []]; foreach ($packages_config as $package => $installed) { $is_installed = false; $proc = Util::process($this->output, "npm -j ls -g {$package}", ['stderr' => false]); if ($proc->isSuccessful()) { $is_installed = false !== stripos($proc->getOutput(), '"' . $package . '": {'); } if ($installed && $is_installed || !$installed && !$is_installed) { continue; } if (!$installed) { $packages['remove'][] = $package; continue; } $packages['install'][] = $package; } foreach ($packages['remove'] as $package) { $this->output->writeInfo("Uninstalling npm package '{$package}'"); $proc = Util::process($this->output, "npm uninstall -g {$package}"); if (!$proc->isSuccessful()) { $this->output->writeError("Error occured uninstalling npm package '{$package}'"); continue; } $this->output->writeInfo("Successfully uninstalled npm package '{$package}'"); } foreach ($packages['install'] as $package) { $this->output->writeInfo("Installing npm package '{$package}'"); $proc = Util::process($this->output, "npm install -g {$package}", ['timeout' => null]); if (!$proc->isSuccessful()) { $this->output->writeError("Error occured while installing npm package '{$package}'"); continue; } $this->output->writeInfo("Successfully installed npm package '{$package}'"); } }