|
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace SixShop\System\Command;
|
|
namespace SixShop\System\Command;
|
|
|
|
|
|
|
|
|
|
+use think\console\input\Argument;
|
|
|
|
|
+use think\console\input\Option;
|
|
|
use think\worker\command\Server;
|
|
use think\worker\command\Server;
|
|
|
use think\worker\Manager;
|
|
use think\worker\Manager;
|
|
|
|
|
|
|
@@ -12,11 +14,38 @@ class WorkerCommand extends Server
|
|
|
public function configure(): void
|
|
public function configure(): void
|
|
|
{
|
|
{
|
|
|
$this->setName('system:worker')
|
|
$this->setName('system:worker')
|
|
|
|
|
+ ->addArgument('action', Argument::OPTIONAL, 'start|stop|restart|reload|status|connections', 'start')
|
|
|
|
|
+ ->addOption('daemon', 'd', Option::VALUE_NONE, 'daemon mode')
|
|
|
|
|
+ ->addOption('grace', 'g', Option::VALUE_NONE, 'graceful shutdown/reload')
|
|
|
->setDescription('Workerman Server for ThinkPHP (with env detection)');
|
|
->setDescription('Workerman Server for ThinkPHP (with env detection)');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function handle(Manager $manager)
|
|
public function handle(Manager $manager)
|
|
|
{
|
|
{
|
|
|
|
|
+ $action = $this->input->getArgument('action') ?: 'start';
|
|
|
|
|
+ $grace = $this->input->getOption('grace');
|
|
|
|
|
+
|
|
|
|
|
+ // think\worker\Worker 禁用了 parseCommand(),需手动处理控制命令
|
|
|
|
|
+ if ($action !== 'start') {
|
|
|
|
|
+ $pidFile = runtime_path() . 'worker.pid';
|
|
|
|
|
+ $masterPid = is_file($pidFile) ? (int) file_get_contents($pidFile) : 0;
|
|
|
|
|
+
|
|
|
|
|
+ if ($masterPid <= 0 || !posix_kill($masterPid, 0)) {
|
|
|
|
|
+ $this->output->error('Worker is not running');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ match ($action) {
|
|
|
|
|
+ 'stop' => posix_kill($masterPid, $grace ? SIGQUIT : SIGINT),
|
|
|
|
|
+ 'reload' => posix_kill($masterPid, $grace ? SIGUSR2 : SIGUSR1),
|
|
|
|
|
+ 'restart' => posix_kill($masterPid, $grace ? SIGQUIT : SIGINT),
|
|
|
|
|
+ default => null,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ $this->output->info("Worker {$action} signal sent");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$envName = getenv('RUNTIME_ENVIRONMENT') ?: '';
|
|
$envName = getenv('RUNTIME_ENVIRONMENT') ?: '';
|
|
|
if (getenv('IS_DDEV_PROJECT') == 'true') {
|
|
if (getenv('IS_DDEV_PROJECT') == 'true') {
|
|
|
$envName = 'ddev';
|
|
$envName = 'ddev';
|