Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel echo server killed on exit console

i'm using laravel-echo-server and all works fine, if i launch server with this command:

laravel-echo-server start

i see:

L A R A V E L E C H O S E R V E R

version 1.2.8

Starting server...

✔  Running at localhost on port 3001
✔  Channels are ready.
✔  Listening for http events...
✔  Listening for redis events...

Server ready!

But if i close with ctrl+c the server has been killed! the same things if i use this command:

laravel-echo-server start &

if i disconnect my ssh connection, the server stop work!

How can i launch in background mode?

thanks!

like image 344
Luca Becchetti Avatar asked Jun 17 '17 13:06

Luca Becchetti


2 Answers

I recommend to use the pm2 tool to manage the larval-echo-server service. After install pm2 you must create a json file inside the Laravel project with a content like this:

echo-pm2.json

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

Then run the next command to start the service in background:

pm2 start echo-pm2.json

Yo can use pm2 monit command for real time monitoring or pm2 logs to get the service logs as well.

like image 170
J.C. Gras Avatar answered Nov 09 '22 21:11

J.C. Gras


Install Supervisor on linux. Here is a manual: https://laravel.com/docs/5.4/queues#supervisor-configuration

Here is my supervisor config file:

[program:websocket-server]
process_name=%(program_name)s
directory=/var/www/example.de/public_html/
command=/usr/lib/node_modules/laravel-echo-server/bin/server.js start
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/example.de/logs/websocket-server.log

Now you can start the server in the background with supervisorctl start websocket-server:*

like image 28
poldixd Avatar answered Nov 09 '22 21:11

poldixd