【问题标题】:Run gunicorn like service像服务一样运行 gunicorn
【发布时间】:2018-08-24 08:53:44
【问题描述】:

我想在服务中配置 gunicorn。

我有这个服务配置:

[Unit]
Description=test

[Service]
WorkingDirectory=/var/www/cmdb
Type=forking
Restart=always
ExecStart=/var/www/test/bin/gunicorn --workers=4 --bind=0.0.0.0:8080 test.wsgi:application

[Install]
WantedBy=multi-user.target

我的问题是它没有运行。启动服务时出现此错误:

gunicorn.service: Main process exited, code=exited, status=203/EXEC
gunicorn.service: Unit entered failed state.
gunicorn.service: Failed with result 'exit-code'.
gunicorn.service: Start request repeated too quickly.

我在我的配置中没有发现错误。有人有想法吗?

【问题讨论】:

    标签: gunicorn systemd


    【解决方案1】:

    假设你在 virtualenv 中运行,gunicorn bin 应该是这样的:

    /var/www/cmdb/venv/bin/gunicorn
    

    代替

    /var/www/test/bin/gunicorn
    

    无论如何,我在我的系统中使用了类似的东西并且它工作正常:

    [Unit]
    Description = SampleApp
    After = network.target
    
    [Service]
    PIDFile = /run/cmdb/cmdb.pid
    WorkingDirectory = /var/www/cmdb
    ExecStartPre = /bin/mkdir /run/cmdb
    ExecStart = /var/www/cmdb/venv/bin/gunicorn test.wsgi:application -b 0.0.0.0:8000 --pid /run/cmdb/cmdb.pid
    ExecReload = /bin/kill -s HUP $MAINPID
    ExecStop = /bin/kill -s TERM $MAINPID
    ExecStopPost = /bin/rm -rf /run/cmdb
    
    [Install]
    WantedBy = multi-user.target
    

    注意:本示例使用 root 作为应用用户。我确实建议使用具有受限权限的用户来访问您的应用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-30
      • 1970-01-01
      • 1970-01-01
      • 2012-06-18
      • 2020-10-06
      • 2020-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多