Sergei
12/12/2024, 1:31 AMMarvin
12/12/2024, 1:31 AMSergei
12/12/2024, 1:31 AMSergei
12/12/2024, 1:31 AMMarvin
12/12/2024, 1:37 AMSergei
12/12/2024, 2:03 AMMarvin
12/12/2024, 2:05 AMsystemd
to manage these processes. Here's a general guide on how to create systemd services for Prefect server and worker:
### Running Prefect as a Systemd Service on Ubuntu
#### Step 1: Create a User
It's best practice to run services under a dedicated user account.
bash
sudo adduser prefect
#### Step 2: Create Systemd Service for Prefect Server
1. Create a service file for Prefect server:
bash
sudo nano /etc/systemd/system/prefect-server.service
2. Add the following configuration, updating paths and commands as necessary to your installation:
ini
[Unit]
Description=Prefect Server
After=network.target
[Service]
User=prefect
WorkingDirectory=/path/to/your/project
ExecStart=/usr/local/bin/prefect server start
Restart=always
[Install]
WantedBy=multi-user.target
#### Step 3: Create Systemd Service for Prefect Worker
1. Create a service file for Prefect worker:
bash
sudo nano /etc/systemd/system/prefect-worker.service
2. Add the following configuration:
ini
[Unit]
Description=Prefect Worker
After=network.target
[Service]
User=prefect
WorkingDirectory=/path/to/your/project
ExecStart=/usr/local/bin/prefect worker start
Restart=always
[Install]
WantedBy=multi-user.target
#### Step 4: Enable and Start Services
Enable the services so they start on boot:
bash
sudo systemctl enable prefect-server
sudo systemctl enable prefect-worker
Start the services:
bash
sudo systemctl start prefect-server
sudo systemctl start prefect-worker
#### Step 5: Verify Services
Check the status of your services:
bash
sudo systemctl status prefect-server
sudo systemctl status prefect-worker
By following these steps, you create long-running, resilient services for your Prefect server and worker on Ubuntu, achieving a robust setup. And isn’t it reassuring to have little automated workers tirelessly keeping your Prefect world in order?
For more information, you can refer to the Prefect Daemonization Guide (if life makes you a systems administrator, learn to dance with systemd
).