sid heart
sid heart

Reputation: 1149

is there any command manager for Laravel artisan

i have few commands in my laravel production app.

php artisan serve

php artisan queue:work

php artisan roulette:color

php artisan roulette:even

i am using vpn with ubuntu custom host

right now i am making 4 different screen for running these commands which is run forever

but sometime few crash don't know why and i have to find again which screen have crashed command

i am seeking is there any manager that can manage my commands easily

thank you

Upvotes: 1

Views: 1175

Answers (2)

mohammadreza khalifeh
mohammadreza khalifeh

Reputation: 1618

you don't need to make 4 different screens, just run:

nohup php artisan queue:work --daemon &

this will prevent the command exiting when you log out. the trailing ampersand (&) causes process starts in the background, so you can continue to use the shell and do not have to wait until the script is finished.

you can run any shell command in the background by adding the & to the end:

nohup php artisan serve &

Installing Supervisor

Supervisor is a process monitor for the Linux operating system, and will automatically restart your queue:work process if it fails. To install Supervisor on Ubuntu, you may use the following command:

sudo apt-get install supervisor

Configuring Supervisor

create laravel-worker.conf in the /etc/supervisor/conf.d directory:

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/laravel-example/artisan queue:work sqs --sleep=3 --tries=3
autostart=true
autorestart=true
user=forge
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/laravel-example//storage/logs/supervisord.log
stopwaitsecs=3600

you can see Supervisor: A Process Control System and Supervisor Configuration in Laravel doc for more info

Upvotes: 1

MrEduar
MrEduar

Reputation: 1941

Supervisor is a process monitor for the Linux operating system, and will automatically restart your queue:work process if it fails or keep any other command active. To install Supervisor on Ubuntu, you may use the following command: sudo apt-get install supervisor.

Configuring Supervisor

Supervisor configuration files are typically stored in the /etc/supervisor/conf.d directory. Within this directory, you may create any number of configuration files that instruct supervisor how your processes should be monitored. For example, let's create a laravel-worker.conf file that starts and monitors a queue:work process:

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/path/to/you/app.com/artisan queue:work sqs --sleep=3 --tries=3
autostart=true
autorestart=true
user=forge
numprocs=8
redirect_stderr=true
stdout_logfile=/home/path/to/you/app.com/worker.log
stopwaitsecs=3600

In this example, the numprocs directive will instruct Supervisor to run 8 queue:work processes and monitor all of them, automatically restarting them if they fail. You should change the queue:work sqs portion of the command directive to reflect your desired queue connection.

Starting Supervisor

Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:

sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl start laravel-worker:*

For more information on Supervisor, consult the Supervisor documentation.

Upvotes: 1

Related Questions