后端在系统启动时关闭

1 投票
1 回答
570 浏览
提问于 2025-04-18 13:30

我在lighttpd上使用python(通过fastcgi)。当我用 /etc/init.d/lighttpd start 启动服务器时,一切都正常。

但是现在我把它添加到了系统的启动项中,用 update-rc.d lighttpd defaults 60,然后重启后,我在错误日志中看到了这个问题:

2011-03-24 22:57:01: (log.c.164) server started
2011-03-24 22:57:42: (mod_fastcgi.c.1754) connect failed: Connection refused on unix:/tmp/dvr.sock-0
2011-03-24 22:57:42: (mod_fastcgi.c.3021) backend died; we'll disable it for 1 seconds and send the request to another backend instead: reconnects: 0 load: 1
2011-03-24 22:57:55: (mod_fastcgi.c.2562) unexpected end-of-file (perhaps the fastcgi process died): pid: 1509 socket: unix:/tmp/dvr.sock-0
2011-03-24 22:57:55: (mod_fastcgi.c.3299) child exited, pid: 1509 status: 1
2011-03-24 22:57:55: (mod_fastcgi.c.3346) response not received, request sent: 858 on socket: unix:/tmp/dvr.sock-0 for /dvr.fcgi?, closing connection

不过在我执行 /etc/init.d/lighttpd restart 后,它又开始正常工作了。

1 个回答

1

我忘了说,我在我的flask项目中使用了环境变量来选择设置文件。这个变量是设置在 /etc/profile 里的,所以我才能从命令行正确启动项目。

所以在我的情况下,我需要通过 bin-environment 选项把这个变量传递给lighttpd,这样它才能在fcgi脚本中使用:

fastcgi.server = (
    "/dvr.fcgi" => (
        "main" => (
            "socket" => "/tmp/dvr.sock",
            "bin-path" => "/var/www/dvr/conf/lighttpd/dvr.fcgi",
            "bin-environment" => (
                    "DVR_SETTINGS" => "/var/www/dvr/settings/production.py"
            ),
            "check-local" => "disable",
            "max-procs" => 1,
        )
    ),
)

撰写回答