https://prefect.io logo
Title
t

Tony Alfonse

02/23/2023, 11:32 PM
Hey Everyone! How can I set up prefect service in Linux within a conda environment? I created this initiate.sh shell file:
#!/bin/bash
eval "$(conda shell.bash hook)"
conda activate ETL
prefect server start
And created this systemd service:
[Unit]
Description=Prefect

[Service]
Type=simple
ExecStart=/home/zeephremia/files_required/initate.sh
User=root
Group=root

[Install]
WantedBy=multi-user.target
Whenever I run the shell script locally, it works but whenever the systemd service triggers it, it throws this error:
prefect_service.service - Prefect
     Loaded: loaded (/etc/systemd/system/prefect_service.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Thu 2023-02-23 23:29:43 UTC; 3s ago
    Process: 2233 ExecStart=/home/zeephremia/files_required/initate.sh (code=exited, status=0/SUCCESS)
   Main PID: 2233 (code=exited, status=0/SUCCESS)

Feb 23 23:29:43 linux-server systemd[1]: Started Prefect.
Feb 23 23:29:43 linux-server initate.sh[2233]: Starting the script...
Feb 23 23:29:43 linux-server initate.sh[2234]: /home/zeephremia/files_required/initate.sh: line 5: conda: command not found
Feb 23 23:29:43 linux-server initate.sh[2235]: /home/zeephremia/files_required/initate.sh: line 6: conda: command not found
Feb 23 23:29:43 linux-server initate.sh[2237]: /home/zeephremia/files_required/initate.sh: line 7: prefect: command not found
Feb 23 23:29:43 linux-server initate.sh[2233]: Script completed.
Feb 23 23:29:43 linux-server systemd[1]: prefect_service.service: Succeeded.
Would really appreciate any help, thank you! 🙂
✅ 1
r

Ryan Peden

02/24/2023, 2:28 AM
I think that instead of writing the initiate script, in the
[Service]
section you could do something like:
ExecStart=/home/myuser/.conda/envs/my_env/bin/prefect server start
The executable script that gets generated when you install Prefect in a conda environment should automatically use the Python installation for that environment even if that env isn't currently activated.