问下为啥我用pm2启动Workerman的Gateway启动失败?

zxcv

问题描述

这里详细描述问题
情况是这样的,我的服务器系统是windows10.然后我想能让程序能后台运行,不要出现命令行窗口,我试着下载Gateway的demo,然后点击start_for_win.bat, 这时候是可以使用的,但是会出现一个命令行窗口,当我关闭命令行窗口时候就不能使用了。

后面我将gateway放到laravel框架里面。然后执行laravel里面的command命令,发现还是会有一个cmd命令行。

后面我想通过PM2来管理进程,让进程能自动重启,启动不起来

我想问的是如何能不要出现cmd命令行的后台运行,主要是我担心服务器上后期会将命令行窗口关掉

程序代码

laravel框架里面的Gateway代码

"workerman/gateway-worker": "^3.1",
"workerman/gatewayclient": "^3.0",
"workerman/workerman": "^4.1"
```php
<?php

namespace App\Console\Commands;

use App\Http\Controllers\IndexController;
use GatewayWorker\BusinessWorker;
use GatewayWorker\Gateway;
use GatewayWorker\Register;
use Illuminate\Console\Command;
use Workerman\Worker;

class WorkermanCommand extends Command
{

    protected $description = 'Start a Workerman server.';

    protected $signature = 'workerman
                            {action : action}
                            {--start=all : start}
                            {--d : daemon mode}';
    public function handle() {
        global $argv;
        $action = $this->argument('action');
        /**
         * 针对 Windows 一次执行,无法注册多个协议的特殊处理
         */
        if ($action === 'single') {
            $start = $this->option('start');
            if ($start === 'register') {
                $this->startRegister();
            } elseif ($start === 'gateway') {
                $this->startGateWay();
            } elseif ($start === 'worker') {
                $this->startBusinessWorker();
            }
            Worker::runAll();

            return;
        }
        /**
         * argv[0] 默认是,当前文件,可以不修改
         */
        //$argv[0] = 'wk';
        $argv[1] = $action;
        // 控制是否进入 daemon 模式
        $argv[2] = $this->option('d') ? '-d' : '';
        $this->start();
    }
    private function start()
    {
        $this->startGateWay();
        $this->startBusinessWorker();
        $this->startRegister();
        Worker::runAll();
    }
    private function startBusinessWorker()
    {
        $worker                  = new BusinessWorker();
        $worker->name            = 'BusinessWorker';
        $worker->count           = 3;
        $worker->registerAddress = '127.0.0.1:1236';
        $worker->eventHandler    = IndexController::class;
    }
    private function startGateWay()
    {
        $gateway = new Gateway("websocket://0.0.0.0:2346");
        $gateway->name                 = 'Gateway';
        $gateway->count                = 2;
        $gateway->lanIp                = '127.0.0.1';
        $gateway->startPort            = 2300;
        $gateway->pingInterval         = 300;
        $gateway->pingNotResponseLimit = 0;
        $gateway->pingData             = '{"type":"ping"}';
        $gateway->registerAddress      = '127.0.0.1:1236';
    }
    private function startRegister()
    {
        new Register('text://0.0.0.0:1236');
    }
}
然后设置 start_for_win.bat
start /b php artisan workerman single --start=register
start /b php artisan workerman single --start=gateway
start /b php artisan workerman single --start=worker

然后我pm2 start start_for_win.bat
结果就是error了
 id │ name      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ worker    │ default     │ N/A     │ cluster │ 1732     │ 0      │ 1    │ stopped   │ 0%       │ 0b       │ test     │ disabled

#### 报错信息

PM2 启动时候报错了

start_for_win.bat
start /b php artisan workerman single --start=register
start /b php artisan workerman single --start=gateway
start /b php artisan workerman single --start=worker

然后我pm2 start start_for_win.bat

id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ worker │ default │ N/A │ cluster │ 1732 │ 0 │ 1 │ stopped │ 0% │ 0b │ yegm │ disabled



#### 操作系统及workerman/webman等框架组件具体版本

windows10
436 1 0
1个回答

nitron
pm2 start some.bat --interpreter none

来自PM2的GH Issue

  • nitron 2024-03-15

    多提一句,正经生产服务器就不要用Windows了

  • zxcv 2024-03-15

    但是我加了--interpreter none就一直弹命令行窗口,关不掉

  • nitron 2024-03-15

    那我就不清楚了,没在windows下用过

×
🔝