Woraphon Tontaweewong
06/28/2025, 2:19 AMMarvin
06/28/2025, 2:19 AMMarvin
06/28/2025, 2:20 AM/etc/systemd/system/prefect-worker.service
):
ini
[Unit]
Description=Prefect Worker Service
After=network.target
[Service]
Type=simple
User=prefect
Environment="PREFECT_API_URL=<http://127.0.0.1:4200/api>"
ExecStart=/usr/local/bin/prefect worker start -p 'your-work-pool-name'
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
2. Similarly, create a service file for the Prefect server if you haven't already (e.g., /etc/systemd/system/prefect-server.service
):
ini
[Unit]
Description=Prefect Server Service
After=network.target
[Service]
Type=simple
User=prefect
ExecStart=/usr/local/bin/prefect server start
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
3. Enable and start the services:
bash
# Reload systemd to recognize new service files
sudo systemctl daemon-reload
# Enable services to start on boot
sudo systemctl enable prefect-server
sudo systemctl enable prefect-worker
# Start the services
sudo systemctl start prefect-server
sudo systemctl start prefect-worker
Some important considerations:
- Make sure to replace your-work-pool-name
with your actual work pool name
- Adjust the PREFECT_API_URL
if your server is running on a different port
- The User=prefect
line assumes you've created a dedicated system user called "prefect" - adjust this as needed
- The Restart=always
ensures the services automatically restart if they crash
- You can check the status of your services using:
bash
sudo systemctl status prefect-server
sudo systemctl status prefect-worker
This setup ensures both your Prefect server and worker run as background services, automatically start on system boot, and restart if they crash. You can view logs using `journalctl`:
bash
journalctl -u prefect-server
journalctl -u prefect-worker