python,django,wsgi应用程式无法运作

时间:2018-08-10 10:36:20

标签: django wsgi nixos

问题

我们想使用WSGI运行taiga.io,但尝试1小时后,我们需要其他人的帮助。我们对查询不满意,但我们认为我们现在运行正确的wsgi二进制文件:

gunicorn taiga.wsgi

但是

  1. 该Web服务仍然无法启动并返回无用的跟踪。
  2. 我们已经对其进行了搜索,并尝试了各种黑客手段,但似乎都没有用。
  3. 我们尝试设置DJANGO_SETTINGS_MODULE,但不确定是否需要
  4. 我们甚至不知道django是否在调用正确的wsgi二进制文件

那为什么工人不能启动?在某处为工人提供更详细的调试吗?

版本

  • taiga-back-3.3.13
  • python3.6-Django-1.11.13
  • python3.6.5
  • gunicorn-19.7.1
  • nixos版本18.03.d6c6c7f-nixcloud_598d0c5(Impala)

任务:通过wsgi运行taiga

目前,我正在将https://github.com/betaboon/nixpkgs/blob/445563d6575d7e8cb21768570b837ea3d816dee8/nixos/modules/services/web-apps/taiga.nix集成到nixcloud-webservices中,并且运行良好:

${taiga-back}/bin/manage.py runserver --nostatic "127.0.0.1:8000"

我们遇到了wsgi的问题:

systemd.services.taiga-back = rec {
 description = "${config.uniqueName} main service (taigaio)";

  wantedBy      = [ "multi-user.target" ];
  after         = [ "network.target" ];

  environment = let
    python = pkgs.python3;
    penv = python.buildEnv.override {
      extraLibs = [
        taiga-back
        pkgs.python3Packages.gunicorn
        pkgs.python3Packages.gevent
        pkgs.python3Packages.celery
        pkgs.python3Packages.django
      ];
    };
  in {
    PYTHONPATH = "${taigaBackConfigPkg}:${penv}/${python.sitePackages}/:${taiga-back}/lib/python3.6/site-packages";
    DJANGO_SETTINGS_MODULE = "settings";
  };
  serviceConfig = {
    User = "taigaio-t1";  # FIXME hardcoded
    Group = "taigaio-t1"; # FIXME hardcoded
    WorkingDirectory = "${config.stateDir}/www";
    PrivateTmp = false;
    # FIXME: hardcoded taigaio-t1 user/group
    # FIXME: port 8000 is hardcoded
    ExecStart =

${pkgs.python3Packages.gunicorn}/bin/gunicorn taiga.wsgi \
        -k gevent \
        -u taigaio-t1 \
        -g taigaio-t1 \
        --name gunicorn-taiga \
        --log-level ${if config.enableDebug then "debug" else "info"} \
        --workers ${toString config.wsgiWorkers} \
        --pid ${config.stateDir}/www/gunicorn-taiga.pid \
        --bind 127.0.0.1:8000

系统作业

[Unit]
After=network.target taigaio-t1-instance-init.target
Description=taigaio-t1 main service (taigaio)

[Service]
Environment="DJANGO_SETTINGS_MODULE=settings"
Environment="LOCALE_ARCHIVE=/nix/store/v2hvbpzhndgjm04djqql93bmb4w69gql-glibc-locales-2.26-131/lib/locale/locale-archive"
Environment="PATH=/nix/store/920k63py2w97xpfyb5ps9l6wbidvzfjz-coreutils-8.29/bin:/nix/store/hlgglqv1vm88frmysq2laifavxjhaf55-findutils-4.6.0/bin:/nix/store/iywd02hbirf506q740z0v6zyrvsa9gcf-gnugrep-3.1/bin:/nix/store/wkgszaq2dkc4asapcbx6ypd7xdnzad9f-gnused-4.4/bin:/nix/store/hjgd23fmmkfxyq896xwyarvgm81274an-systemd-237/bin:/nix/store/920k63py2w97xpfyb5ps9l6wbidvzfjz-coreutils-8>
Environment="PYTHONPATH=/nix/store/llhzay9fjzswcx2gdi9jvwswa9c2axwv-taiga-back-config-package:/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/:/nix/store/d9i1q6xv61dv93hsv8bklkvn5nl2g7sc-taiga-back-3.3.13/lib/python3.6/site-packages"
Environment="TZDIR=/nix/store/k8n4sf0yfas70yfv156knrpv9xfipjwm-tzdata-2017c/share/zoneinfo"



ExecStart=/nix/store/v3cicrbs6adk379h2625kwviaxq7697h-python3.6-gunicorn-19.7.1/bin/gunicorn taiga.wsgi \
            -k gevent \
            -u taigaio-t1 \
            -g taigaio-t1 \
            --name gunicorn-taiga \
            --log-level debug \
            --workers 3 \
            --pid /var/lib/nixcloud/webservices/taigaio-t1/www/gunicorn-taiga.pid \
            --bind 127.0.0.1:8000

Group=taigaio-t1
PermissionsStartOnly=true
PrivateDevices=true
PrivateTmp=false
Restart=always
TimeoutSec=300
User=taigaio-t1
WorkingDirectory=/var/lib/nixcloud/webservices/taigaio-t1/www

新闻日志

Aug 10 10:21:59 michiel systemd[1]: Started taigaio-t1 main service (taigaio).
Aug 10 10:21:59 michiel gunicorn[10927]: [2018-08-10 10:21:59 +0000] [10927] [DEBUG] Current configuration:
Aug 10 10:21:59 michiel gunicorn[10927]:   config: None
Aug 10 10:21:59 michiel gunicorn[10927]:   bind: ['127.0.0.1:8000']
Aug 10 10:21:59 michiel gunicorn[10927]:   backlog: 2048
Aug 10 10:21:59 michiel gunicorn[10927]:   workers: 3
Aug 10 10:21:59 michiel gunicorn[10927]:   worker_class: gevent
Aug 10 10:21:59 michiel gunicorn[10927]:   threads: 1
Aug 10 10:21:59 michiel gunicorn[10927]:   worker_connections: 1000
Aug 10 10:21:59 michiel gunicorn[10927]:   max_requests: 0
Aug 10 10:21:59 michiel gunicorn[10927]:   max_requests_jitter: 0
Aug 10 10:21:59 michiel gunicorn[10927]:   timeout: 30
Aug 10 10:21:59 michiel gunicorn[10927]:   graceful_timeout: 30
Aug 10 10:21:59 michiel gunicorn[10927]:   keepalive: 2
Aug 10 10:21:59 michiel gunicorn[10927]:   limit_request_line: 4094
Aug 10 10:21:59 michiel gunicorn[10927]:   limit_request_fields: 100
Aug 10 10:21:59 michiel gunicorn[10927]:   limit_request_field_size: 8190
Aug 10 10:21:59 michiel gunicorn[10927]:   reload: False
Aug 10 10:21:59 michiel gunicorn[10927]:   reload_engine: auto
Aug 10 10:21:59 michiel gunicorn[10927]:   spew: False
Aug 10 10:21:59 michiel gunicorn[10927]:   check_config: False
Aug 10 10:21:59 michiel gunicorn[10927]:   preload_app: False
Aug 10 10:21:59 michiel gunicorn[10927]:   sendfile: None
Aug 10 10:21:59 michiel gunicorn[10927]:   chdir: /var/lib/nixcloud/webservices/taigaio-t1/www
Aug 10 10:21:59 michiel gunicorn[10927]:   daemon: False
Aug 10 10:21:59 michiel gunicorn[10927]:   raw_env: []
Aug 10 10:21:59 michiel gunicorn[10927]:   pidfile: /var/lib/nixcloud/webservices/taigaio-t1/www/gunicorn-taiga.pid
Aug 10 10:21:59 michiel gunicorn[10927]:   worker_tmp_dir: None
Aug 10 10:21:59 michiel gunicorn[10927]:   user: 1013
Aug 10 10:21:59 michiel gunicorn[10927]:   group: 486
Aug 10 10:21:59 michiel gunicorn[10927]:   umask: 0
Aug 10 10:21:59 michiel gunicorn[10927]:   initgroups: False
Aug 10 10:21:59 michiel gunicorn[10927]:   tmp_upload_dir: None
Aug 10 10:21:59 michiel gunicorn[10927]:   secure_scheme_headers: {'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-PROTO': 'https', 'X-FORWARDED-SSL': 'on'}
Aug 10 10:21:59 michiel gunicorn[10927]:   forwarded_allow_ips: ['127.0.0.1']
Aug 10 10:21:59 michiel gunicorn[10927]:   accesslog: None
Aug 10 10:21:59 michiel gunicorn[10927]:   access_log_format: %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
Aug 10 10:21:59 michiel gunicorn[10927]:   errorlog: -
Aug 10 10:21:59 michiel gunicorn[10927]:   loglevel: debug
Aug 10 10:21:59 michiel gunicorn[10927]:   capture_output: False
Aug 10 10:21:59 michiel gunicorn[10927]:   logger_class: gunicorn.glogging.Logger
Aug 10 10:21:59 michiel gunicorn[10927]:   logconfig: None
Aug 10 10:21:59 michiel gunicorn[10927]:   syslog_addr: udp://localhost:514
Aug 10 10:21:59 michiel gunicorn[10927]:   syslog: False
Aug 10 10:21:59 michiel gunicorn[10927]:   syslog_prefix: None
Aug 10 10:21:59 michiel gunicorn[10927]:   syslog_facility: user
Aug 10 10:21:59 michiel gunicorn[10927]:   enable_stdio_inheritance: False
Aug 10 10:21:59 michiel gunicorn[10927]:   statsd_host: None
Aug 10 10:21:59 michiel gunicorn[10927]:   statsd_prefix:
Aug 10 10:21:59 michiel gunicorn[10927]:   proc_name: gunicorn-taiga
Aug 10 10:21:59 michiel gunicorn[10927]:   default_proc_name: taiga.wsgi
Aug 10 10:21:59 michiel gunicorn[10927]:   pythonpath: None
Aug 10 10:21:59 michiel gunicorn[10927]:   paste: None
Aug 10 10:21:59 michiel gunicorn[10927]:   on_starting: <function OnStarting.on_starting at 0x7fd3ea5d7f28>
Aug 10 10:21:59 michiel gunicorn[10927]:   on_reload: <function OnReload.on_reload at 0x7fd3ea5ea158>
Aug 10 10:21:59 michiel gunicorn[10927]:   when_ready: <function WhenReady.when_ready at 0x7fd3ea5ea2f0>
Aug 10 10:21:59 michiel gunicorn[10927]:   pre_fork: <function Prefork.pre_fork at 0x7fd3ea5ea488>
Aug 10 10:21:59 michiel gunicorn[10927]:   post_fork: <function Postfork.post_fork at 0x7fd3ea5ea620>
Aug 10 10:21:59 michiel gunicorn[10927]:   post_worker_init: <function PostWorkerInit.post_worker_init at 0x7fd3ea5ea7b8>
Aug 10 10:21:59 michiel gunicorn[10927]:   worker_int: <function WorkerInt.worker_int at 0x7fd3ea5ea950>
Aug 10 10:21:59 michiel gunicorn[10927]:   worker_abort: <function WorkerAbort.worker_abort at 0x7fd3ea5eaae8>
Aug 10 10:21:59 michiel gunicorn[10927]:   pre_exec: <function PreExec.pre_exec at 0x7fd3ea5eac80>
Aug 10 10:21:59 michiel gunicorn[10927]:   pre_request: <function PreRequest.pre_request at 0x7fd3ea5eae18>
Aug 10 10:21:59 michiel gunicorn[10927]:   post_request: <function PostRequest.post_request at 0x7fd3ea5eaf28>
Aug 10 10:21:59 michiel gunicorn[10927]:   child_exit: <function ChildExit.child_exit at 0x7fd3ea5ee158>
Aug 10 10:21:59 michiel gunicorn[10927]:   worker_exit: <function WorkerExit.worker_exit at 0x7fd3ea5ee2f0>
Aug 10 10:21:59 michiel gunicorn[10927]:   nworkers_changed: <function NumWorkersChanged.nworkers_changed at 0x7fd3ea5ee488>
Aug 10 10:21:59 michiel gunicorn[10927]:   on_exit: <function OnExit.on_exit at 0x7fd3ea5ee620>
Aug 10 10:21:59 michiel gunicorn[10927]:   proxy_protocol: False
Aug 10 10:21:59 michiel gunicorn[10927]:   proxy_allow_ips: ['127.0.0.1']
Aug 10 10:21:59 michiel gunicorn[10927]:   keyfile: None
Aug 10 10:21:59 michiel gunicorn[10927]:   certfile: None
Aug 10 10:21:59 michiel gunicorn[10927]:   ssl_version: 2
Aug 10 10:21:59 michiel gunicorn[10927]:   cert_reqs: 0
Aug 10 10:21:59 michiel gunicorn[10927]:   ca_certs: None
Aug 10 10:21:59 michiel gunicorn[10927]:   suppress_ragged_eofs: True
Aug 10 10:21:59 michiel gunicorn[10927]:   do_handshake_on_connect: False
Aug 10 10:21:59 michiel gunicorn[10927]:   ciphers: TLSv1
Aug 10 10:21:59 michiel gunicorn[10927]:   raw_paste_global_conf: []

Aug 10 10:21:59 michiel gunicorn[10927]: [2018-08-10 10:21:59 +0000] [10927] [INFO] Starting gunicorn 19.7.1
Aug 10 10:21:59 michiel gunicorn[10927]: [2018-08-10 10:21:59 +0000] [10927] [DEBUG] Arbiter booted
Aug 10 10:21:59 michiel gunicorn[10927]: [2018-08-10 10:21:59 +0000] [10927] [INFO] Listening at: http://127.0.0.1:8000 (10927)
Aug 10 10:21:59 michiel gunicorn[10927]: [2018-08-10 10:21:59 +0000] [10927] [INFO] Using worker: gevent
Aug 10 10:21:59 michiel gunicorn[10927]: [2018-08-10 10:21:59 +0000] [10930] [INFO] Booting worker with pid: 10930
Aug 10 10:21:59 michiel gunicorn[10927]: [2018-08-10 10:21:59 +0000] [10931] [INFO] Booting worker with pid: 10931
Aug 10 10:21:59 michiel gunicorn[10927]: [2018-08-10 10:21:59 +0000] [10932] [INFO] Booting worker with pid: 10932
Aug 10 10:21:59 michiel gunicorn[10927]: [2018-08-10 10:21:59 +0000] [10927] [DEBUG] 3 workers
Aug 10 10:22:00 michiel gunicorn[10927]: Trying import local.py settings...
Aug 10 10:22:00 michiel gunicorn[10927]: Trying import local.py settings...
Aug 10 10:22:00 michiel gunicorn[10927]: Trying import local.py settings...
Aug 10 10:22:00 michiel gunicorn[10927]: Traceback (most recent call last):
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/gunicorn/arbiter.py", line 209, in run
Aug 10 10:22:00 michiel gunicorn[10927]:     self.sleep()
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/gunicorn/arbiter.py", line 359, in sleep
Aug 10 10:22:00 michiel gunicorn[10927]:     ready = select.select([self.PIPE[0]], [], [], 1.0)
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/gunicorn/arbiter.py", line 244, in handle_chld
Aug 10 10:22:00 michiel gunicorn[10927]:     self.reap_workers()
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/gunicorn/arbiter.py", line 524, in reap_workers
Aug 10 10:22:00 michiel gunicorn[10927]:     raise HaltServer(reason, self.WORKER_BOOT_ERROR)
Aug 10 10:22:00 michiel gunicorn[10927]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
Aug 10 10:22:00 michiel gunicorn[10927]: During handling of the above exception, another exception occurred:
Aug 10 10:22:00 michiel gunicorn[10927]: Traceback (most recent call last):
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/v3cicrbs6adk379h2625kwviaxq7697h-python3.6-gunicorn-19.7.1/bin/.gunicorn-wrapped", line 12, in <module>
Aug 10 10:22:00 michiel gunicorn[10927]:     sys.exit(run())
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
Aug 10 10:22:00 michiel gunicorn[10927]:     WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/gunicorn/app/base.py", line 203, in run
Aug 10 10:22:00 michiel gunicorn[10927]:     super(Application, self).run()
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
Aug 10 10:22:00 michiel gunicorn[10927]:     Arbiter(self).run()
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/gunicorn/arbiter.py", line 231, in run
Aug 10 10:22:00 michiel gunicorn[10927]:     self.halt(reason=inst.reason, exit_status=inst.exit_status)
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/gunicorn/arbiter.py", line 344, in halt
Aug 10 10:22:00 michiel gunicorn[10927]:     self.stop()
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/gunicorn/arbiter.py", line 393, in stop
Aug 10 10:22:00 michiel gunicorn[10927]:     time.sleep(0.1)
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/gunicorn/arbiter.py", line 244, in handle_chld
Aug 10 10:22:00 michiel gunicorn[10927]:     self.reap_workers()
Aug 10 10:22:00 michiel gunicorn[10927]:   File "/nix/store/5i07mzahrys0w3bca0zfvrgkcxw14dcx-python3-3.6.5-env/lib/python3.6/site-packages/gunicorn/arbiter.py", line 524, in reap_workers
Aug 10 10:22:00 michiel gunicorn[10927]:     raise HaltServer(reason, self.WORKER_BOOT_ERROR)
Aug 10 10:22:00 michiel gunicorn[10927]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
Aug 10 10:22:00 michiel systemd[1]: taigaio-t1-taiga-back.service: Main process exited, code=exited, status=1/FAILURE
Aug 10 10:22:00 michiel systemd[1]: taigaio-t1-taiga-back.service: Failed with result 'exit-code'.
Aug 10 10:22:01 michiel systemd[1]: taigaio-t1-taiga-back.service: Service hold-off time over, scheduling restart.
Aug 10 10:22:01 michiel systemd[1]: taigaio-t1-taiga-back.service: Scheduled restart job, restart counter is at 2.
Aug 10 10:22:01 michiel systemd[1]: Stopped taigaio-t1 main service (taigaio).

1 个答案:

答案 0 :(得分:1)

好吧,经过几天的尝试,终于可以解决问题了:

问题与下面的代码有关,该代码用于描述环境。稍后,wsgi(gunicorn)服务的PYTHONPATH将不包含taiga-back python库:

  python = pkgs.python3;
  penv = with pkgs.python3Packages; with myPythonPackages;  python.buildEnv.override {
    extraLibs = [
      taiga-back
      pkgs.python3Packages.gunicorn
      pkgs.python3Packages.gevent
    ];
  };

如上所述,PYTHONPATH还应该包含来自proposeddBuildInputs的taiga-back依赖项,但必须在buildPythonPackage上使用buildPythonApplication之后。

构建taiga io后端(Python代码)

-python3Packages.buildPythonApplication rec {
+python3Packages.buildPythonPackage rec {
   pname = "taiga-back";
   version = "3.3.13";
@@ -414,7 +420,7 @@ python3Packages.buildPythonApplication rec {
     sha256 = "1cy5ak7mw9ia9b0d1lil0s6ck87kinrmicsw61m6vpkal1slnnf7";  # 3.3.13
   };