Systemd user services examples

Example for Akeneo, can be used for Laravel and other frameworks:

Create a file:

 ~/.config/systemd/user/pim-job-queue@.service

[Unit]
Description=Akeneo PIM Job Queue Service (#%i)
After=network-online.target
Requires=dbus.socket

[Service]
Type=simple
WorkingDirectory=%h/public_html
ExecStart=%h/bin/console akeneo:batch:job-queue-consumer-daemon --env=prod
RestartSec=10s
Restart=always

[Install]
WantedBy=default.target
 

Notes:

  • Keep the "Requires=dbus.socket" and "After=network-online.target" parts, it is important for the user services to use the proper dependencies.
  • Also keep the "WantedBy=default.target" , because not all other targets are available in systemd user services.
  • You cannot depend on the system services like mysqld, it will not be found by the user services. Possible workarounds may exist...

 

Now enable and start 3 instances for example:

systemctl --user enable pim-job-queue@{1..3}
systemctl --user start pim-job-queue@{1..3}

Restart it:

systemctl --user restart pim-job-queue@*.service

Status:

systemctl --user status pim-job-queue@*.service


Was this article helpful?

mood_bad Dislike 5
mood Like 2
visibility Views: 264

Powered by HostBill