像服务一样运行gunicorn

时间:2018-08-24 08:53:44

标签: gunicorn systemd

我要在服务中配置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.

我在我的配置中找不到错误。有人有主意吗?

1 个答案:

答案 0 :(得分:0)

假设您在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作为应用程序用户。我确实建议您使用具有受限权限的用户。