diff --git a/src/Stages/V1804/CheckServices.php b/src/Stages/V1804/CheckServices.php index c727e4a..a67f73a 100644 --- a/src/Stages/V1804/CheckServices.php +++ b/src/Stages/V1804/CheckServices.php @@ -24,7 +24,6 @@ class CheckServices extends StageBase implements Stage 'nginx' => 'Nginx is not running', 'redis' => 'Redis is not running', 'supervisor' => 'Supervisror is not running', - 'php' . APP_PANEL_PHP_VERSION . '-fpm' => 'PHP FPM is not running', 'unattended-upgrades' => 'Security updates not enabled' ]; @@ -35,6 +34,12 @@ class CheckServices extends StageBase implements Stage public function run(Environment $env): bool { try { + $versions = $env->getArray('php_versions'); + + foreach($versions as $version) { + $this->services["php{$version}-fpm"] = "PHP FPM {$version} is not running"; + } + foreach ($this->services as $service => $error) { if (!$this->active($service, $error)) { return false; diff --git a/src/Stages/V1804/Php.php b/src/Stages/V1804/Php.php index 6a3a0be..4ca9358 100644 --- a/src/Stages/V1804/Php.php +++ b/src/Stages/V1804/Php.php @@ -40,36 +40,46 @@ public function run(Environment $env): bool try { $this->version($env->getArray('php_versions')); - if ( - !$this->write( - "/etc/php/{$php}/fpm/conf.d/sculptor.ini", - $this->template('php.ini'), - 'Cannot write ini configuration' - ) - ) { - return false; - } - - foreach ([ APP_PANEL_HTTP_USER, APP_PANEL_HTTP_PANEL ] as $user) { - if (!$this->pool($php, $user)) { - return false; - } - } + $this->agent($php); - if (!$this->restart("php{$php}-fpm")) { - $this->internal = 'Cannot restart service'; - - return false; - } + $this->command(['update-alternatives', '--set', 'php', '/usr/bin/php' . APP_PANEL_PHP_VERSION]); return true; } catch (Exception $e) { + $this->internal = $e->getMessage(); Log::error($e->getMessage()); return false; } } + /** + * @param string $php + * @return void + */ + private function agent(string $php): void + { + if ( + !$this->write( + "/etc/php/{$php}/fpm/conf.d/sculptor.ini", + $this->template('php.ini'), + 'Cannot write ini configuration' + ) + ) { + throw new Exception("Cannot write php{$php} for sculptor agent"); + } + + foreach ([ APP_PANEL_HTTP_USER, APP_PANEL_HTTP_PANEL ] as $user) { + if (!$this->pool($php, $user)) { + throw new Exception("Cannot write php{$php} for user {$user}"); + } + } + + if (!$this->restart("php{$php}-fpm")) { + throw new Exception("Cannot restart php{$php} service"); + } + } + /** * @param string $php * @param string $user @@ -79,6 +89,7 @@ private function pool(string $php, string $user): bool { $pool = $this->replaceTemplate('php-pool.conf') ->replace("{USER}", $user) + ->replace("{PHP}", $php) ->value(); if (!$this->write("/etc/php/{$php}/fpm/pool.d/{$user}.conf", $pool, "Cannot write pool configuration {$user}")) { @@ -88,7 +99,11 @@ private function pool(string $php, string $user): bool return true; } - private function version(array $versions): bool + /** + * @param array $versions + * @return void + */ + private function version(array $versions): void { foreach ($versions as $version) { $modules = collect($this->modules) @@ -98,12 +113,14 @@ private function version(array $versions): bool $this->command(collect(['apt-get', '-y', 'install'])->concat($modules)->toArray()); - $this->pool($version, APP_PANEL_HTTP_USER); - } - - $this->command(['update-alternatives', '--set', 'php', '/usr/bin/php' . APP_PANEL_PHP_VERSION]); + if (!$this->pool($version, APP_PANEL_HTTP_USER)) { + throw new Exception("Cannot restart php{$version} service"); + } - return true; + if (!$this->restart("php{$version}-fpm")) { + throw new Exception("Cannot restart php{$version} service"); + } + } } /** diff --git a/templates/php-pool.conf b/templates/php-pool.conf index a9fc330..79669ef 100644 --- a/templates/php-pool.conf +++ b/templates/php-pool.conf @@ -1,7 +1,7 @@ [{USER}] user = {USER} group = {USER} -listen = /run/php/php7.4-fpm-{USER}.sock +listen = /run/php/php{PHP}-fpm-{USER}.sock listen.owner = www-data listen.group = www-data pm = ondemand