必须将Dify插件守护进程注册为systemd服务以实现长期运行,具体包括:创建/etc/systemd/system/dify-plugin-daemon.service,正确配置PYTHON_INTERPRETER_PATH、EnvironmentFile及依赖项;执行daemon-reload、enable、start并用status和journalctl验证;同时确保沙盒服务(dify-sandbox.service)已激活且权限正确。
☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 多模态理解力帮你轻松跨越从0到1的创作门槛☜☜☜

配置Dify插件守护进程为系统服务
在Linux服务器上长期运行Dify插件守护进程,必须将其注册为systemd服务,否则终端关闭或系统重启后进程立即终止。这一步是生产环境稳定运行的前提。
进入Dify插件守护进程源码根目录,确认已正确配置.env文件,特别是【PYTHON_INTERPRETER_PATH=/opt/dify-python/bin/python3】——若路径错误,服务启动时会报“Exec format error”并静默失败。
创建服务定义文件:sudo nano /etc/systemd/system/dify-plugin-daemon.service
写入以下内容(注意替换/path/to/dify-plugin-daemon为你的实际路径):
[Unit]
Description=Dify Plugin Daemon
After=network.target redis.service postgresql.service
[Service]
Type=simple
User=dify
WorkingDirectory=/path/to/dify-plugin-daemon
ExecStart=/opt/dify-python/bin/python3 -m dify_plugin_daemon
Restart=always
RestartSec=10
EnvironmentFile=/path/to/dify-plugin-daemon/.env
[Install]
WantedBy=multi-user.target
启用并验证守护进程自启动
第一步:重新加载systemd配置,使新服务被识别:sudo systemctl daemon-reload
第二步:启用开机自启:sudo systemctl enable dify-plugin-daemon.service
第三步:立即启动服务:sudo systemctl start dify-plugin-daemon.service
第四步:检查状态是否为active (running),重点关注Active:行和最后三行日志输出:sudo systemctl status dify-plugin-daemon.service
若看到Failed to start Dify Plugin Daemon,立即执行sudo journalctl -u dify-plugin-daemon.service -n 50 -f查看实时错误日志——90%的问题出在Python路径错误、.env中DB_HOST不可达或Redis未运行。
沙盒服务同步配置(必需配套)
Dify插件守护进程依赖沙盒服务提供代码执行隔离。两者必须同时运行且版本匹配,否则插件调用直接返回500错误。
方法一:复用已有dify-sandbox.service(如已部署)
确认其状态为active:sudo systemctl is-active dify-sandbox.service
若返回inactive,立即启动:sudo systemctl start dify-sandbox.service
方法二:新建沙盒服务(首次部署)
创建/etc/systemd/system/dify-sandbox.service,关键项必须包含:Type=forkingPIDFile=/var/run/dify-sandbox.pidExecStart=/opt/dify-sandbox/bin/dify-sandbox --pidfile /var/run/dify-sandbox.pid start
【务必确保dify用户对/opt/dify-sandbox/有完整读写权限】,否则沙盒启动后无法创建PID文件,systemd判定服务启动失败。


















