Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Replace supervisor with systemd unit #1570

Open
linux019 opened this issue Mar 20, 2019 · 7 comments
Open

Replace supervisor with systemd unit #1570

linux019 opened this issue Mar 20, 2019 · 7 comments

Comments

@linux019
Copy link

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

@linux019 linux019 changed the title Replace supervisor va systemd unit Replace supervisor with systemd unit Mar 20, 2019
@mfn
Copy link

mfn commented Mar 20, 2019

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
Copy link

How do you run multiple queue workers that way?

@linux019
Copy link
Author

linux019 commented Mar 21, 2019

[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
Copy link

ludo237 commented Mar 21, 2019

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

@sisve
Copy link

sisve commented Mar 22, 2019

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.

rubenrua added a commit to rubenrua/Notes that referenced this issue Sep 28, 2019
Supervisor conf from https://symfony.com/doc/current/messenger.html#supervisor-configuration

```
;/etc/supervisor/conf.d/messenger-worker.conf
[program:messenger-consume]
command=php /path/to/your/app/bin/console messenger:consume async --time-limit=3600
user=ubuntu
numprocs=2
autostart=true
autorestart=true
process_name=%(program_name)s_%(process_num)02d
```

systemd conf from: laravel/ideas#1570

PD: Systemd is not 'do one thing and do it well' is a feature creep
@hrvoj3e
Copy link

hrvoj3e commented Aug 4, 2020

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
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants