From 2e8276ca837e1fc5f85f81f153547dda5f027143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 16 Apr 2021 11:36:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Shutdown.php | 8 ++++---- System/Snowflake.php | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/HttpServer/Shutdown.php b/HttpServer/Shutdown.php index 86bf34fa..cf01d194 100644 --- a/HttpServer/Shutdown.php +++ b/HttpServer/Shutdown.php @@ -47,10 +47,10 @@ class Shutdown extends Component public function shutdown(): void { clearstatcache(storage()); -// exec('ls -alh /.dockerenv', $output, $cod); -// if ($cod === 0 && !empty($output)) { -// return; -// } + exec('ls -alh /.dockerenv', $output, $cod); + if ($cod === 0 && !empty($output)) { + return; + } $master_pid = Server()->setting['pid_file'] ?? PID_PATH; if (file_exists($master_pid)) { diff --git a/System/Snowflake.php b/System/Snowflake.php index e1a0a738..32f63c94 100644 --- a/System/Snowflake.php +++ b/System/Snowflake.php @@ -10,7 +10,6 @@ use Database\ActiveRecord; use Database\Collection; use Exception; use HttpServer\IInterface\Task; - use JetBrains\PhpStorm\Pure; use ReflectionException; use Snowflake\Abstracts\Config; @@ -223,6 +222,19 @@ class Snowflake } + /** + * @return bool + */ + public static function isDcoker(): bool + { + exec('ls -alh /.dockerenv', $output, $cod); + if ($cod === 0 && !empty($output)) { + return true; + } + return false; + } + + /** * @param $workerId * @return mixed @@ -230,10 +242,13 @@ class Snowflake */ public static function setWorkerId($workerId): mixed { - if (empty($workerId)) { + if (empty($workerId) || static::isDcoker()) { return $workerId; } - return self::writeFile(storage($workerId . '.sock', 'pid/worker'), $workerId); + + $tmpFile = storage($workerId . '.sock', 'pid/worker'); + + return self::writeFile($tmpFile, $workerId); } @@ -504,7 +519,6 @@ class Snowflake } - /** * @return string|null */