Most of our customers run on maxcluster servers and therefore we use supervisord, which is brought by the setup. But one of our newer clients brought their own hosting and there was no supervisord, but systemd. So it was time to fiddle out, how to run Shopware queue workers and scheduled task with it.
supervisord and systemd are pretty similar – at least from the point of view of a PHP and Shopware developer ? . First we setup services, then we combine them into a group (it seems to be called “target” in systemd ?) and voilá, done.
Setup services
From this point on, everything I do is via a root account!
If you want to understand the details, I can recommend the blog articles by Benjamin Morel and Steven Rombauts who helped me a lot to make this work. Especially what the different lines do and why I need an @ in one of the filenames.
Systemd configurations living in /etc/systemd/system
, so we create the two services there.
# Filename: shopware-message-consume@.service
[Unit]
Description=shopware messenger:consume
After=mysqld.service
StartLimitIntervalSec=0
PartOf=shopware.target
[Service]
Type=simple
Restart=always
RestartSec=1
User=www-data
ExecStart=/usr/bin/env php /var/www/bin/console messenger:consume --time-limit=300 --memory-limit=512M async default -v
[Install]
WantedBy=multi-user.target
# Filename: shopware-scheduled-task.service
[Unit]
Description=shopware scheduled tasks
After=mysqld.service
StartLimitIntervalSec=0
PartOf=shopware.target
[Service]
Type=simple
Restart=always
RestartSec=1
User=www-data
ExecStart=/usr/bin/env php /var/www/bin/console scheduled-task:run --memory-limit=512M --time-limit=300 -v
[Install]
WantedBy=multi-user.target
Group them
# Filename: shopware.target
[Unit]
Description=shopware Worker
Wants=shopware-message-consume@1.service shopware-message-consume@2.service shopware-message-consume@3.service shopware-message-consume@4.service shopware-message-consume@5.service shopware-scheduled-task.service
[Install]
WantedBy=multi-user.target
Start your new service(s)
Once this is done, you need to reload the config of systemd and then you can start your service.
systemctl daemon-reload
systemctl start shopware.target