正在尝试在ubuntu上部署django应用程序。
start-server.sh具有
cd /home/django
source env/bin/activate
cd tutorial
gunicorn tutorial.wsgi如果我大写start-server.sh,那么一切都运行得很好。
所以,我写了以下内容。
gunicorn.service保存在/etc/systemd/system/中,如下所示
[Unit]
Description=Gunicorn
After=network.target
[Service]
Type=simple
User=django
ExecStart=/bin/bash /home/django/bin/start-server.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target然后我跑
sudo systemctl enable gunicorn
sudo systemctl start gunicorn但现在我看到了502错误。当我使用start-server.sh时,一切都很完美。但是,不知何故,与黑角兽不起作用。
guincorn版本18.0(我尝试了20.0,但没有成功)
sudo systemctl状态gunicorn显示
● gunicorn.service - Gunicorn
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-06-09 16:56:59 UTC; 2min 5s ago
Main PID: 26285 (code=exited, status=126)
Jun 09 16:56:58 ip-184-168-120-14.ip.secureserver.net systemd[1]: gunicorn.service: Main process exited, code=exited, status=126/n/a
Jun 09 16:56:58 ip-184-168-120-14.ip.secureserver.net systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jun 09 16:56:59 ip-184-168-120-14.ip.secureserver.net systemd[1]: gunicorn.service: Scheduled restart job, restart counter is at 5.
Jun 09 16:56:59 ip-184-168-120-14.ip.secureserver.net systemd[1]: Stopped Gunicorn.
Jun 09 16:56:59 ip-184-168-120-14.ip.secureserver.net systemd[1]: gunicorn.service: Start request repeated too quickly.
Jun 09 16:56:59 ip-184-168-120-14.ip.secureserver.net systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jun 09 16:56:59 ip-184-168-120-14.ip.secureserver.net systemd[1]: Failed to start Gunicorn.发布于 2021-06-10 05:13:36
在start-server.sh的顶部添加以下行
#!/bin/bash这就是所谓的"shebang“线。类ends系统通常不会注意文件扩展名,因此会忽略文件名以.sh结尾的事实。系统查找这一行是为了确定该文件将由bash执行。
此外,您需要确保该文件是可执行的:
chown +x /home/django/bin/start-server.sh但是,您实际上根本不需要start-server.sh,因为它所做的一切都可以由systemd完成。将以下行添加到[Service]部分:
WorkingDirectory=/home/django/tutorial并将ExecStart替换为以下内容:
ExecStart=/home/django/env/bin/gunicorn tutorial.wsgi就这样。如果你觉得它令人困惑,请阅读virtualenv demystified。
发布于 2021-06-10 01:15:05
不要在bash脚本中执行cd-commands,而是使用完整路径
source /home/django/env/bin/activate
gunicorn /home/django/env/bin/activate/tutorial.wsgihttps://stackoverflow.com/questions/67908796
复制相似问题