Issue with keeping Agents alive with Supervisor. I...
# prefect-community
e
Issue with keeping Agents alive with Supervisor. I am having an issue with properly initialising supervisor to keep my agents running. I have generated the generic supervisor code but I keep getting the following error messages: "can't find command 'prefect'". Any ideas what might be the issue here? This is my supervisor code:
Copy code
[unix_http_server]
file=/tmp/supervisor.sock

[supervisord]
loglevel=debug

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[program:local-agent]
command=prefect agent local start -l local

[program:docker-agent]
command=prefect agent docker start -l docker
The main issue I am trying to solve is keeping the agent up and running at all times. My VM does a scheduled restart once a day which means any agents I spin up manually will be shut down. Is there any way of setting the agent itself up as a docker container which starts on startup like the prefect server itself? It seems like the docker agent itself isnt actually running in docker but rather just issues the flow to its own docker container?
a
This page gives more details but you shouldn’t run Docker agent in a container, it should run as a local process. It looks like you need to install prefect. If you have some issues installing Prefect, you can try using a Conda virtual env instead. You can then use a supervisor file as follows (adjust to the name of your virtual env):
Copy code
[unix_http_server]
file=/tmp/supervisor.sock   ; the path to the socket file

[supervisord]
loglevel=debug               ; log level; default info; others: debug,warn,trace

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[program:prefect-agent]
command=/Users/anna/opt/anaconda3/envs/YOUR_ENV_NAME/bin/prefect agent docker start -l docker
e
Ah, that does make a lot of sense. Thank you for super speedy reply. I am a bit confused though, as when I issue the command in my command line it runs fine, just not through the supervisor. Ill try the virtual env.
👍 1
Hey @Anna Geller, I ended up solving this with the following code. It seems Supervisor couldnt do any commands at all without specifying a shell in the command. Is it meant to work without specifying the shell?
Copy code
command=/bin/bash -c 'source ~/python-environments/prefect/bin/activate && prefect agent docker start -l docker'
I am still however having issues with getting supervisor to restart on boot of the VM though. I get this: "_unix:///tmp/supervisor.sock"_ no such file error after a restart. Could it be because the socket file is saved in the tmp folder?
a
That's what I wanted to ask - where did you store all the files 🙂 it's often better to store this file in some custom directory under home and then you can start your supervisor with the -c flag to provide custom file path:
Copy code
supervisord -c ./supervisord.conf
This way you don't need any privileged permissions to access such directory upon reboot