laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

Replace supervisor with systemd unit #1570

Open linux019 opened 5 years ago

linux019 commented 5 years ago

As almost linux distros have been shipped with powerful systemd daemon it's not neccessary to install supervisord it to run queus A simple unit like that does all the job

[Unit]
Description=Laravel queue worker

[Service]
User=www-data
Group=www-data
Restart=on-failure
ExecStart=/usr/bin/php /laravel/artisan queue:work

[Install]
WantedBy=multi-user.target

you have to place it in /etc/systemd/system systemctl daemon-reload systemctl enable laravel-queue.service systemctl start laravel-queue.service

mfn commented 5 years ago

In reality, there is nothing to replace because supervisor is just a suggestion; i.e. there's no real technical dependency on it. Of course I see that the docs talk only about it, as this is just the way the docs were written.

I suggest you rather make a nice documentation PR how one can use systemd with the workers (and also horizon) so we all can benefit from it.

IMO this is a complex topic, it would be nice if it would cover everything the current guide for supervisor covers (i.e. stdout/stderr log redirection, max restart tries, etc.)

thannaske commented 5 years ago

How do you run multiple queue workers that way?

linux019 commented 5 years ago
[Unit]
Description=Laravel queues

[Service]
User=www-user
Group=www-user
Type=simple
Restart=on-failure
RestartSec=30
Nice=10
WorkingDirectory=/www/laravel/
ExecStart=/usr/bin/php artisan queue:work --queue=default --sleep=30 --timeout=1800 --tries=1 --memory=256
StandardOutput=null
TimeoutStartSec=30
[Install]
RequiredBy=multi-user.target

This one works for me well but it's not indeed to Ctrl+C and Ctrl+V into projects. To run multiple workers you have to list them in "queue" parameter, add more lines ExecStart or create mutiple service units

ludo237 commented 5 years ago

Agree with @mfn this is a DOC pr rather than an idea for Laravel

sisve commented 5 years ago

Using systemd for multiple workers quickly becomes weird. You cannot list them in the queue parameter as suggested, this just adds more queues to the responsibility of a single worker process. I don't think that a systemd unit with type=simple supports several ExecStart.

A quick look around makes me think we need some a parent unit and several child units, where the child units uses WantedBy=parent-unit.target and PartOf=parent-unit.target, so when you start/stop the parent the children will also be affected. You would also need a WantedBy=multi-user.target if you want to start them when booting. It seems it can be done, but it will require more configuration that suggested.

Supervisor's numprocs=3 makes this really easy.

hrvoj3e commented 4 years ago

Could this help? https://unix.stackexchange.com/a/288310

/etc/systemd/system/test@.service - the important bit is the @ symbol

Still, Supervisor's numprocs=3 looks better - but systemd is already there. Also, systemd units/targets can be started from an unprivileged user.

abhyudayasrinet commented 3 years ago

If you're using Laravel with AWS Elasticbeanstalk, AWS EB doesn't provide supervisor out of the box and I ended up integrating systemd. Helpful instructions: https://serverfault.com/questions/987069/how-to-make-laravel-queue-work-in-aws-beanstalk