Stable Diffusion守护进程

今天在Ubuntu中给部署的Stable Diffusion设置进程守护遇见了一个小问题在这里给大家分享出来

问题还原

给Stable Diffusion使用Supervisor设置守护进程的时候发现一直启动失败,测试了好几次命令都是这样的。下面给大家还原一下:

image-20240411134639898

在控制台中使用命令:

conda activate webui && sh webui.sh --listen --enable-insecure-extension-access

启动没有问题

这个命令又两个命令构成一个是conda activate webui用于切换虚拟环境,webui.sh --listen --enable-insecure-extension-access这个是启动命令。

但是在Supervisor中就一直不行。报错信息如下:

2024-04-11 02:53:19,600 CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message.
2024-04-11 02:53:19,600 INFO Included extra file "/www/server/panel/plugin/supervisor/profile/SD.ini" during parsing 
2024-04-11 02:53:19,903 INFO RPC interface 'supervisor' initialized 
2024-04-11 02:53:19,903 CRIT Server 'unix_http_server' running without any HTTP authentication checking 
2024-04-11 02:53:19,904 INFO daemonizing the supervisord process 
2024-04-11 02:53:19,905 INFO supervisord started with pid 20598 
2024-04-11 02:53:20,908 INFO spawned: 'SD_00' with pid 20609 
2024-04-11 02:53:20,934 INFO exited: SD_00 (exit status 1; not expected) 2024-04-11 02:53:21,937 INFO spawned: 'SD_00' with pid 20611 
2024-04-11 02:53:21,951 INFO exited: SD_00 (exit status 1; not expected) 2024-04-11 02:53:23,956 INFO spawned: 'SD_00' with pid 20612 
2024-04-11 02:53:23,981 INFO exited: SD_00 (exit status 1; not expected) 2024-04-11 02:53:26,988 INFO spawned: 'SD_00' with pid 20615 
2024-04-11 02:53:27,014 INFO exited: SD_00 (exit status 1; not expected) 2024-04-11 02:53:28,015 INFO gave up: SD_00 entered FATAL state, too many start retries too quickly 
2024-04-11 02:53:37,267 INFO spawned: 'SD_00' with pid 20620 
2024-04-11 02:53:37,292 INFO exited: SD_00 (exit status 1; not expected) 2024-04-11 02:53:38,296 INFO spawned: 'SD_00' with pid 20621 
2024-04-11 02:53:38,321 INFO exited: SD_00 (exit status 1; not expected) 2024-04-11 02:53:40,327 INFO spawned: 'SD_00' with pid 20622 
2024-04-11 02:53:40,352 INFO exited: SD_00 (exit status 1; not expected)

解决方案

就是这个conda命令找不到让我摸不着头脑,不知道自己出错在了哪里。一直到翻阅文档才看到:

在Supervisor的配置文件中,command字段是用来指定启动进程时执行的完整命令。在Linux shell环境下,conda activate命令不是一个单独的可执行文件,而是conda环境的一个内部机制,直接在Supervisor的command字段中使用可能会导致无法识别。

所以说:

conda activate命令的作用是在当前shell会话中临时修改环境变量,使得后续命令能够在指定的conda环境中执行。然而,Supervisor执行命令时并不会像交互式shell那样维持环境更改,因此直接写成conda activate webui && sh webui.sh --listen可能无法激活相应的conda环境。

那找到了问题之后就可以修改supervisor的配置

在Supervisor配置中,我们需要使用/bin/bash -c的方式来模拟一个完整的shell会话,这样bash就可以执行多条命令并在同一进程中保持环境更改。在bash会话中,先执行source /stable-diffusion-webui/venv/bin/activate来激活conda环境,然后再执行sh webui.sh --listen启动你的服务。这样一来,webui.sh就是在激活后的conda环境中执行的,从而确保能够正确找到并使用环境中的软件包和设置。

[program:SD]
command=/bin/bash -c "source /stable-diffusion-webui/venv/bin/activate && sh /stable-diffusion-webui/webui.sh --listen --enable-insecure-extension-access"
directory=/stable-diffusion-webui/
autorestart=true
startsecs=3
startretries=3
stdout_logfile=/www/server/panel/plugin/supervisor/log/SD.out.log
stderr_logfile=/www/server/panel/plugin/supervisor/log/SD.err.log
stdout_logfile_maxbytes=2MB
stderr_logfile_maxbytes=2MB
user=haohao
priority=999
numprocs=1
process_name=%(program_name)s_%(process_num)02d

大家按需修改自己的command参数就可以。

Was this helpful?

0 / 0

发表回复 0

Your email address will not be published.