Service (Systemd)
RoadRunner Service Plugin provides a simple API to monitor and control processes. It is often used to manage background processes, daemons, or services that need to run continuously. The Service Plugin allows you to start, stop, and manage any number of processes, including PHP scripts, binaries, and bash/powershell scripts.
Manage services using RoadRunner config
The Service Plugin is configured using a .rr.yaml
.
Here is an example configuration:
The service
section is where you define your services, with each service having its own configuration settings.
Configuration Settings
The following are the available configuration settings for each service:
Setting | Description |
---|---|
command | The command to execute. There are no restrictions on commands. It could be a binary, a PHP file, a script, etc. |
process_num | The number of processes for the command to fire. The default value is |
exec_timeout | The maximum allowed time to run for the process. The default value is 0s, which means unlimited time. The timeout can be set in the form of |
timeout_stop_sec | The maximum allowed time to wait for the process to stop. |
remain_after_exit | If set to |
restart_sec | The delay between process stop and restart. The default value is 30 seconds. |
service_name_in_log | If set to |
env | Environment variables to pass to the underlying process from the config. |
user | Username (not UID) for the Service process. An empty value means to use the RR process user. |
Services will be started when RoadRunner starts and will be stopped when RoadRunner stops. |
PHP client
The RoadRunner Service Plugin PHP Client Library allows you to manage processes in PHP application using the Service Plugin. You can use the library to create, start, stop, restart, and manage any number of services.
Installation
You can install the package via composer:
Usage
To use the library, you need to create an instance of Spiral\RoadRunner\Services\Manager
:
Create a service
To create a new service, use the create
method:
Checking Service Status
To check the status of a service, use the statuses
method:
Restarting a Service
To restart a service, use the restart
method:
Terminating a Service
To terminate a service, use the terminate
method:
When you're terminating the service, RR sends the SIGINT
signal to the underlying process(ses).
Listing All Services
To get a list of all services, use the list
method:
API
Protobuf API
To make it easy to use the Service proto API in PHP, we provide a GitHub repository, that contains all the generated PHP DTO classes proto files, making it easy to work with these files in your PHP application.
Last updated