<@ULVA73B9P> Can I execute CLI command to start a ...
# marvin-ai
j
@Marvin Can I execute CLI command to start a worker in --detached mode? If not, why this was not implemented yet, are there any reason? Ex.: prefect worker start --pool test-work-pool --detached
m
thought for 135.5 seconds
Short answer: there isn’t a
--detached
flag for
prefect worker start
in Prefect 3.x. Why it’s not there: - Prefect intentionally doesn’t implement process supervision/daemonization in the CLI. Backgrounding a long‑running process is best handled by your OS or orchestrator (systemd, Docker, Kubernetes, etc.) to get proper restart policies, logging, and signal handling across platforms. - I couldn’t find an official rationale or issue specifically discussing a
--detached
flag. Docs: Workers (Prefect 3.x) Common ways to run a worker “detached”: - Linux/macOS (quick and dirty):
Copy code
nohup prefect worker start --pool test-work-pool > worker.out 2>&1 & disown
or run in `tmux`/`screen`. - systemd (recommended on Linux):
Copy code
[Unit]
  Description=Prefect Worker
  After=network.target

  [Service]
  Type=simple
  User=prefect
  WorkingDirectory=/opt/prefect
  Environment="PREFECT_API_URL=..."
  Environment="PREFECT_API_KEY=..."
  ExecStart=/usr/bin/env bash -lc 'prefect worker start --pool test-work-pool'
  Restart=always
  RestartSec=5
  StandardOutput=append:/var/log/prefect-worker.log
  StandardError=append:/var/log/prefect-worker.err

  [Install]
  WantedBy=multi-user.target
Then:
Copy code
sudo systemctl daemon-reload
  sudo systemctl enable --now prefect-worker.service
- Docker (let Docker do the daemonization):
Copy code
docker run -d --name prefect-worker \
    -e PREFECT_API_URL=... \
    -e PREFECT_API_KEY=... \
    your-prefect-image \
    prefect worker start --pool test-work-pool
- Kubernetes: run the worker as a Deployment so it’s always on and restarted by the scheduler. If you’d like a native
--detached
, feel free to open a feature request: Create a Prefect issue. If you share your environment (OS, container/orchestrator, how you deploy), I can give you a tailored, copy‑paste setup.
n
@Jackson Freitas this exists for
prefect server start
I could see why this might be useful, but can you explain your use case?
there's no specific reason this doesn't exist outside of lack of demand
j
Hi @Nate, I was testing the CLI, and creating a worker and a pool on the same time with command prefect worker start -p "my-pool" --type "process". But my cmd kept occupied with process all the time, so, looking for informations on API I don't search the --detached resource. I know this exist for server, but why don't exist for worker?
n
> there's no specific reason this doesn't exist outside of lack of demand feel free to open an issue!
👍 1
j
@Nate Issue oppend on Github issue!
n
great thanks!