django – 运行两个gunicorn
试图在gunicorn上运行两个站点来编辑服务
[Unit] Description=gunicorn daemon After=network.target [Service] User=ubuntu Group=www-data WorkingDirectory=/home/ubuntu/webapps/kenyabuzz ExecStart=/home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/kenyabuzz/kb.sock kb.wsgi:application [Install] WantedBy=multi-user.target 至 [Unit] Description=gunicorn daemon After=network.target [Service] User=ubuntu Group=www-data WorkingDirectory=/home/ubuntu/webapps/kenyabuzz WorkingDirectory=/home/ubuntu/webapps/uganda_buzz ExecStart=/home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/kenyabuzz/kb.sock kb.wsgi:application ExecStart=/home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/uganda_buzz/ug.sock kb.wsgi:application [Install] WantedBy=multi-user.target 日志显示ExecStart不能重复 ubuntu@ip-172-31-17-122:~$sudo systemctl status gunicorn ● gunicorn.service - gunicorn daemon Loaded: error (Reason: Invalid argument) Active: active (running) since Tue 2017-02-14 09:36:52 EAT; 35s ago Main PID: 26150 (gunicorn) CGroup: /system.slice/gunicorn.service ├─26150 /home/ubuntu/webapps/djangoenv/bin/python /home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/kenyabuzz/kb.sock kb.wsgi:application ├─26156 /home/ubuntu/webapps/djangoenv/bin/python /home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/kenyabuzz/kb.sock kb.wsgi:application ├─26157 /home/ubuntu/webapps/djangoenv/bin/python /home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/kenyabuzz/kb.sock kb.wsgi:application └─26160 /home/ubuntu/webapps/djangoenv/bin/python /home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/kenyabuzz/kb.sock kb.wsgi:application Feb 14 09:36:52 ip-172-31-17-122 systemd[1]: Started gunicorn daemon. Feb 14 09:36:52 ip-172-31-17-122 gunicorn[26150]: [2017-02-14 09:36:52 +0000] [26150] [INFO] Starting gunicorn 19.6.0 Feb 14 09:36:52 ip-172-31-17-122 gunicorn[26150]: [2017-02-14 09:36:52 +0000] [26150] [INFO] Listening at: unix:/home/ubuntu/webapps/kenyabuzz/kb.sock (26150) Feb 14 09:36:52 ip-172-31-17-122 gunicorn[26150]: [2017-02-14 09:36:52 +0000] [26150] [INFO] Using worker: sync Feb 14 09:36:52 ip-172-31-17-122 gunicorn[26150]: [2017-02-14 09:36:52 +0000] [26156] [INFO] Booting worker with pid: 26156 Feb 14 09:36:52 ip-172-31-17-122 gunicorn[26150]: [2017-02-14 09:36:52 +0000] [26157] [INFO] Booting worker with pid: 26157 Feb 14 09:36:52 ip-172-31-17-122 gunicorn[26150]: [2017-02-14 09:36:52 +0000] [26160] [INFO] Booting worker with pid: 26160 Feb 14 09:37:15 ip-172-31-17-122 systemd[1]: gunicorn.service: Service has more than one ExecStart= setting,which is only allowed for Type=oneshot services. Refusing. 在这种情况下,使用可用配置运行两个站点的最佳方法是什么.在空格和逗号分隔的同一行上尝试每个都会带来错误. 解决方法
systemd对这种情况有很大的支持.我假设你在应用程序前面运行像Nginx这样的Web服务器作为反向代理,使用它们唯一的套接字名称将流量路由到每个Gunicorn实例的右端点.在这里,我将重点介绍systemd配置.
希望能够停止并启动一个独立的gunicorn实例,并且还希望将它们视为可以一起停止或启动的单个服务. systemd解决方案涉及创建“目标”,该目标将用于将两个实例视为单个服务.然后,将使用单个“模板单元”允许您向“目标”添加多个gunicorns. 首先,/ etc / systemd / systemd / gunicorn.target: # See ReADME.md for more about this file [Unit] Description=Gunicorn Documentation=https://example.com/path/to/your/docs [Install] WantedBy=multi-user.target 而已.您已经创建了一个目标,当“启用”将在启动时启动.现在/etc/systemd/system/gunicorn@.service,模板文件: [Unit] Description=gunicorn daemon After=network.target PartOf=gunicorn.target # Since systemd 235 reloading target can pass through ReloadPropagatedFrom=gunicorn.target [Service] User=ubuntu Group=www-data WorkingDirectory=/home/ubuntu/webapps/%i ExecStart=/home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/%i/kb.sock kb.wsgi:application [Install] WantedBy=gunicorn.target 请注意我对您的文件所做的更改: >每个实例现在是PartOf =目标. 要立即启动或停止所有Gunicorn实例,我们可以简单地: systemctl start gunicorn systemctl stop gunicorn 我们可以使用启用和禁用来动态添加和删除新的Gunicorn实例: systemctl enable gunicorn@kenyabuzz systemctl disable gunicorn@ugandabuzz 我们也可以自行停止并启动特定服务: systemctl start gunicorn@kenyabuzz systemctl stop gunicorn@kenyabuzz systemctl restart gunicorn@kenyabuzz 要了解有关所使用的任何系统指令的更多信息,您可以查看man systemd.directives,它将列出记录每个指令的特定手册页. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |