Sam*_* M. 2 django gunicorn systemd
试图在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
Run Code Online (Sandbox Code Playgroud)
至
[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
Run Code Online (Sandbox Code Playgroud)
日志显示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.
Run Code Online (Sandbox Code Playgroud)
在这种情况下,使用可用配置运行两个站点的最佳方法是什么.在空格和逗号分隔的同一行上尝试每个都会带来错误.
Mar*_*erg 12
systemd对这种情况有很大的支持.我假设你在应用程序前面运行像Nginx这样的Web服务器作为反向代理,使用它们唯一的套接字名称将流量路由到每个Gunicorn实例的右端点.在这里,我将重点介绍systemd配置.
希望能够停止和启动一个单独的gunicorn实例,并且还希望将它们视为single service可以一起停止或启动的实例.
该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
Run Code Online (Sandbox Code Playgroud)
而已.您已经创建了一个目标,当"启用"将在启动时启动.现在/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
Run Code Online (Sandbox Code Playgroud)
请注意我对您的文件所做的更改:
PartOf=都是目标.WantedBy=WorkingDirectory=插座路径现在使用的变量,因为该文件现在是一个模板.要立即启动或停止所有Gunicorn实例,我们可以简单地:
systemctl start gunicorn.target
systemctl stop gunicorn.target
Run Code Online (Sandbox Code Playgroud)
我们可以使用enable和动态disable添加和删除新的Gunicorn实例:
systemctl enable gunicorn@kenyabuzz
systemctl disable gunicorn@ugandabuzz
Run Code Online (Sandbox Code Playgroud)
我们还可以自己stop和start特定的服务:
systemctl start gunicorn@kenyabuzz
systemctl stop gunicorn@kenyabuzz
systemctl restart gunicorn@kenyabuzz
Run Code Online (Sandbox Code Playgroud)
要了解有关所使用的任何系统指令的更多信息,您可以查看gunicorn.service,其中将列出记录每个指令的特定手册页.
| 归档时间: |
|
| 查看次数: |
3131 次 |
| 最近记录: |