Bläddra i källkod

Avoid dumping if the server is not ready

Jordi Boggiano 6 år sedan
förälder
incheckning
38ec7725d3

+ 14 - 3
src/Packagist/WebBundle/HealthCheck/MetadataDirCheck.php

@@ -18,13 +18,24 @@ class MetadataDirCheck extends AbstractCheck
         $this->awsMeta = $awsMetadata;
         $this->awsMeta = $awsMetadata;
     }
     }
 
 
+    public static function isMetadataStoreMounted(array $awsMeta): bool
+    {
+        if ($awsMeta['primary'] && $awsMeta['has_instance_store']) {
+            // TODO in symfony4, use fromShellCommandline
+            $proc = new Process('lsblk -io NAME,TYPE,SIZE,MOUNTPOINT,FSTYPE,MODEL | grep Instance | grep sdeph');
+            if (0 !== $proc->run()) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
     public function check()
     public function check()
     {
     {
         if ($this->awsMeta['primary']) {
         if ($this->awsMeta['primary']) {
             if ($this->awsMeta['has_instance_store']) {
             if ($this->awsMeta['has_instance_store']) {
-                // TODO in symfony4, use fromShellCommandline
-                $proc = new Process('lsblk -io NAME,TYPE,SIZE,MOUNTPOINT,FSTYPE,MODEL | grep Instance | grep sdeph');
-                if (0 !== $proc->run()) {
+                if (!self::isMetadataStoreMounted($this->awsMeta)) {
                     return new Failure('Instance store needs configuring');
                     return new Failure('Instance store needs configuring');
                 }
                 }
             }
             }

+ 12 - 1
src/Packagist/WebBundle/Package/SymlinkDumper.php

@@ -20,6 +20,7 @@ use Symfony\Component\Finder\Finder;
 use Packagist\WebBundle\Entity\Version;
 use Packagist\WebBundle\Entity\Version;
 use Packagist\WebBundle\Entity\Package;
 use Packagist\WebBundle\Entity\Package;
 use Doctrine\DBAL\Connection;
 use Doctrine\DBAL\Connection;
+use Packagist\WebBundle\HealthCheck\MetadataDirCheck;
 use Predis\Client;
 use Predis\Client;
 
 
 /**
 /**
@@ -111,6 +112,11 @@ class SymlinkDumper
      */
      */
     private $compress;
     private $compress;
 
 
+    /**
+     * @var array
+     */
+    private $awsMeta;
+
     /**
     /**
      * Constructor
      * Constructor
      *
      *
@@ -121,7 +127,7 @@ class SymlinkDumper
      * @param string                $targetDir
      * @param string                $targetDir
      * @param int                   $compress
      * @param int                   $compress
      */
      */
-    public function __construct(RegistryInterface $doctrine, Filesystem $filesystem, UrlGeneratorInterface $router, Client $redis, $webDir, $targetDir, $compress)
+    public function __construct(RegistryInterface $doctrine, Filesystem $filesystem, UrlGeneratorInterface $router, Client $redis, $webDir, $targetDir, $compress, $awsMetadata)
     {
     {
         $this->doctrine = $doctrine;
         $this->doctrine = $doctrine;
         $this->fs = $filesystem;
         $this->fs = $filesystem;
@@ -131,6 +137,7 @@ class SymlinkDumper
         $this->buildDir = $targetDir;
         $this->buildDir = $targetDir;
         $this->compress = $compress;
         $this->compress = $compress;
         $this->redis = $redis;
         $this->redis = $redis;
+        $this->awsMeta = $awsMetadata;
     }
     }
 
 
     /**
     /**
@@ -142,6 +149,10 @@ class SymlinkDumper
      */
      */
     public function dump(array $packageIds, $force = false, $verbose = false)
     public function dump(array $packageIds, $force = false, $verbose = false)
     {
     {
+        if (MetadataDirCheck::isMetadataStoreMounted($this->awsMeta)) {
+            throw new \RuntimeException('Metadata store not mounted, can not dump metadata');
+        }
+
         $cleanUpOldFiles = date('i') == 0;
         $cleanUpOldFiles = date('i') == 0;
 
 
         // prepare build dir
         // prepare build dir

+ 1 - 1
src/Packagist/WebBundle/Resources/config/services.yml

@@ -67,7 +67,7 @@ services:
     packagist.package_dumper:
     packagist.package_dumper:
         public: true
         public: true
         class: Packagist\WebBundle\Package\SymlinkDumper
         class: Packagist\WebBundle\Package\SymlinkDumper
-        arguments: [ '@doctrine', '@filesystem', '@router', '@snc_redis.default_client', '%kernel.root_dir%/../web/', '%packagist_metadata_dir%', '%packagist_dumper_compress%' ]
+        arguments: [ '@doctrine', '@filesystem', '@router', '@snc_redis.default_client', '%kernel.root_dir%/../web/', '%packagist_metadata_dir%', '%packagist_dumper_compress%', '%aws_metadata%' ]
 
 
     packagist.user_provider:
     packagist.user_provider:
         class: Packagist\WebBundle\Security\Provider\UserProvider
         class: Packagist\WebBundle\Security\Provider\UserProvider