无法使用主管启动 laravel-echo-server

Can't start laravel-echo-server with supervisor

我已经参考了人们在其他 post 上提出的所有其他建议,但没有任何效果。

相关文件的路径

我的项目的根目录是 /var/www/html,那是我有 .envlaravel-echo-server.json.

的地方

我在全局安装了 laravel-echo-server。我可以 运行 它成功地来自 laravel-echo-server start --dir=/path/to/project/root

当我运行which laravel-echo-server时,显示其路径为~/.nvm/versions/node/v13.5.0/bin/laravel-echo-server

同样,节点的路径是~/.nvm/versions/node/v13.5.0/bin/node

我的主管工作人员的 conf 文件位于 /etc/supervisor/conf.d/laravel-echo-server.conf

supervisor 运行s其他worker成功,比如Horizo​​n,所以不是supervisor配置的问题。

配置文件

[program:laravel-echo-server]
process_name=%(program_name)s_%(process_num)02d
command=laravel-echo-server start --dir=/var/www/html
autostart=true
numprocs=1
user=root
autorestart=true
stdout_logfile=/var/log/workers/laravel-echo-server.log

我还尝试了以下命令行变体:

command=/usr/bin/laravel-echo-server start --dir=/var/www/html
command=~/.nvm/versions/node/v13.5.0/bin/laravel-echo-server --dir=/var/www/html

所有这些尝试和变化return ERROR (no such file).

我还尝试复制 laravel-echo-server.json 以放置在 /usr/bin/etc/supervisor/conf.d 等位置,但这没有帮助。

我还尝试将用户从 root 更改为 ec2-user(这是我可以从命令行成功初始化 laravel-echo-server 的用户名)。

我也尝试添加另一行:directory=/var/www/html 但这没有帮助。

Shell 可执行尝试

我试图制作一个主管可以调用的 shell 可执行文件。这是文件:

#!/bin/bash
exec laravel-echo-server start --dir=../../../var/www/html

我这样用主管调用可执行文件:

command=bash -c laravel-echo-server.sh

但它 returned ERROR (spawn error)

附加信息

supervisord.conf

[inet_http_server]
port=*:9001

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisord]
;http_port=/var/tmp/supervisor.sock ; (default is to run a UNIX domain socket server)
;http_port=127.0.0.1:9001  ; (alternately, ip_address:port specifies AF_INET)
;sockchmod=0700              ; AF_UNIX socketmode (AF_INET ignore, default 0700)
;sockchown=nobody.nogroup     ; AF_UNIX socket uid.gid owner (AF_INET ignores)
;umask=022                   ; (process file creation umask;default 022)
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB       ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10          ; (num of main logfile rotation backups;default 10)
loglevel=info               ; (logging level;default info; others: debug,warn)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false              ; (start in foreground if true;default false)
minfds=1024                 ; (min. avail startup file descriptors;default 1024)
minprocs=200                ; (min. avail process descriptors;default 200)

;nocleanup=true              ; (don't clean up tempfiles at start;default false)
;http_username=user          ; (default is no username (open system))
;http_password=123           ; (default is no password (open system))
;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
;user=chrism                 ; (default is current user, required if root)
;directory=/tmp              ; (default is not to cd during start)
;environment=KEY=value       ; (key value pairs to add to environment)

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as http_username if set
;password=123                ; should be same as http_password if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")

[include]
files = /etc/supervisor/conf.d/*.conf

laravel-echo-server.json

{
    "authHost": http://mywebsite.com,
    "authEndpoint": "/broadcasting/auth",
    "clients": [],
    "database": "redis",
    "databaseConfig": {
        "redis": {[my redis credentials]},
        "sqlite": {
            "databasePath": "/database/laravel-echo-server.sqlite"
        }
    },
    "devMode": true,
    "host": null,
    "port": "6001",
    "protocol": "http",
    "socketio": {},
    "sslCertPath": "",
    "sslKeyPath": "",
    "sslCertChainPath": "",
    "sslPassphrase": "",
    "subscribers": {
        "http": true,
        "redis": true
    },
    "apiOriginAllow": {
        "allowCors": false,
        "allowOrigin": "",
        "allowMethods": "",
        "allowHeaders": ""
    }
}

更新

现在我试过了:

command=/home/ec2-user/.nvm/versions/node/v13.5.0/bin/laravel-echo-server start --dir=/var/www/html

根据 post 评论中的建议。然而那是 returning ERROR (spawn error)

当我检查 supervisord.log 时,它显示如下:

2019-12-31 07:27:05,869 INFO exited: laravel-echo-server_00 (exit status 127; not expected)

退出状态代码 127 显然意味着“找不到命令”。

所以在放弃 运行 使用 composer 之后,使用 pm2 运行 变得最容易了。

这是我的 .ebextensions 命令:

sudo yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_13.x | sudo -E bash -
sudo yum install -y nodejs
npm config set scripts-prepend-node-path true
npm install -g laravel-echo-server
npm install -g pm2@latest
pm2 start laravel-echo-server-pm2.json

还有我的 pm2 json:

{
  "name": "laravel-echo-server",
  "script": "laravel-echo-server",
  "args": "start"
}

我还向 .ebextensions 添加了一些命令,允许我修改我的 .env 文件。更改会覆盖写入 laravel-echo-server.json 的值。这样,我不必每次从开发切换到生产时都更改它们:

echo "LARAVEL_ECHO_SERVER_REDIS_HOST=production-redis-host.com" >> .env
echo "LARAVEL_ECHO_SERVER_REDIS_PORT=6379" >> .env
echo "LARAVEL_ECHO_SERVER_DEBUG=false" >> .env