Systemd

Configuring unit

Here you can find an example of systemd unit file that can be used to run RoadRunner as a daemon on a server:

rr.service
[Unit]
Description=High-performance PHP application server
Documentation=https://docs.roadrunner.dev/

[Service]
ExecStart=/usr/local/bin/rr serve -c /var/www/.rr.yaml

Type=notify

# Prevent systemd from terminating the worker processes
KillMode=mixed

# Adjust this to the value in jobs.pool.destroy_timeout
TimeoutStopSec=30

Restart=always
RestartSec=30

[Install]
WantedBy=default.target 

Where:

  • /usr/local/bin/rr - path to the RoadRunner binary file

  • /var/www/.rr.yaml - path to the RoadRunner configuration file

These paths are just examples, and the actual paths may differ depending on the specific server configuration and file locations. You should update these paths to match the actual paths used in your server setup.

You should also update the ExecStart option with your own configuration and save the file with a suitable name, such as rr.service. Usually, such user unit files are located in the .config/systemd/user/ directory. To enable the service, you should run the following commands:

systemctl enable --user rr.service

and

systemctl start rr.service

This will start RoadRunner as a daemon on the server.

For more information about systemd unit files, the user can refer to the following link.

Status and logs

Make sure that the systemd service has started successfully, use the command:

systemctl status rr.service

Example output:

● rr.service - High-performance PHP application server
     Loaded: loaded (/lib/systemd/system/rr.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2024-03-12 19:20:55 UTC; 35min ago
     Docs: https://docs.roadrunner.dev/
     CGroup: /system.slice/rr.service
             β”œβ”€2835793 /usr/local/bin/rr serve -c /var/www/.rr.yaml
             β”œβ”€2895807 /usr/local/bin/php worker.php
             β”œβ”€2897198 /usr/local/bin/php worker.php
             β”œβ”€2897765 /usr/local/bin/php worker.php

To view logs in real time, use the command:

journalctl -f -u rr.service

Example output with info level logs:

Mar 12 20:12:53 server systemd[1]: Starting PHP application server...
Mar 12 20:12:55 server rr[2936506]: [INFO] RoadRunner server started; version: 2023.3.10, buildtime: 2024-02-01T22:33:17+0000
Mar 12 20:12:55 server rr[2936506]: [INFO] sdnotify: notified
Mar 12 20:12:55 server systemd[1]: Started PHP application server.

sd_notify protocol

Roadrunner supports sd_notify protocol. You can use it to notify systemd about the readiness of your application. Don't forget to add Type=notify directive to the Service section, Roadrunner will automatically detect systemd and send the notification. The only one option which might be configured is watchdog timeout. By default, it's turned off. You can enable it by setting the following option in your .rr.yaml config:

.rr.yaml
endure:
  log_level: error
  watchdog_sec: 60 # watchdog timeout in seconds

Last updated