我无法在 ec2 实例中设置 Gunicorn 守护进程。以下是示例代码和错误/日志消息。
myproject-backend/gunicorn.conf
import os
import multiprocessing
from dotenv import load_dotenv
# load .env file
APP_ROOT = os.path.dirname(__file__)
dotenv_path = os.path.join(APP_ROOT, '.env')
load_dotenv(dotenv_path=dotenv_path)
# Please refer http://docs.gunicorn.org/en/latest/settings.html# for ducumentation.
bind = os.getenv('GUNICORN_BIND')
workers = multiprocessing.cpu_count() * 2 + 1
daemon = True
preload = True
reload = False
umask = os.getenv('GUNICORN_UMASK')
group = os.getenv('GUNICORN_GROUP')
user = os.getenv('GUNICORN_USER')
pythonpath = os.getenv('PYPATH')
myproject-backend/.env
# This will load environment specific dynamic configurations.
# possible value - "development", "testing", "stage", "production"
INSTANCE_TYPE="production"
# gunicorn config
GUNICORN_UMASK=0
GUNICORN_GROUP='ubuntu'
GUNICORN_USER='ubuntu'
GUNICORN_BIND='localhost:8080'
#GUNICORN_BIND='127.0.0.1:8080'
PYPATH='/home/ubuntu/project/myproject-backend/'
/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/project/myproject-backend
ExecStart=/home/ubuntu/project/myproject-backend/.venv/bin/gunicorn -c /home/ubuntu/project/myproject-backend/gunicorn.conf wsgi:app
#ExecStart=/home/ubuntu/project/myproject-backend/.venv/bin/gunicorn --access-logfile - --workers 3 --bind unix::8080 wsgi:app
[Install]
WantedBy=multi-user.target
sudo systemctl状态gunicorn 回报
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Tue 2019-08-27 01:12:22 UTC; 50s ago
Main PID: 4515 (code=exited, status=0/SUCCESS)
Aug 27 01:12:21 ip-172-31-40-176 systemd[1]: Started gunicorn daemon.
。 须藤journalctl -u Gunicorn
8 月 27 日 00:47:15 ip-172-31-40-176 systemd[1]:启动了 Gunicorn 守护进程。 8 月 27 日 00:58:09 ip-172-31-40-176 systemd[1]:启动了 Gunicorn 守护进程。
如果您使用注释ExecStart
行,/etc/systemd/system/gunicorn.service
那么一切看起来都不错,但我想gunicorn
从配置文件运行。这个怎么做?
答案1
gunicorn.cfg
当我更改时在文件中
umask = os.getenv('GUNICORN_UMASK')
group = os.getenv('GUNICORN_GROUP')
user = os.getenv('GUNICORN_USER')
到
umask = 0
user = None
group = None
然后一切看起来都很好。我不知道为什么以及如何。但是的,它解决了问题。如果这里有人可以向我解释那就太好了。