-1

我最近使用 Ubuntu 20.04、gunicorn 和 nginx 部署了一个 django Web 应用程序,Huey 已在本地完美运行。在生产中,我需要使用 systemd 运行 python manage.py run_huey

我已经尝试过这里的建议Can't enable huey service on deploy server but not working。

我的代码类似于该建议。我会感谢任何贡献。提前致谢

4

2 回答 2

1

我可以通过在代码中添加Requires=gunicorn.socket来解决这个问题。现在我的 huey.service 看起来

[Unit]
Description=Huey Service
Requires=gunicorn.socket
After=redis.service

[Service]
User=deploy
Group=www-data
WorkingDirectory=/home/username/projectdir
ExecStart=/home/username/projectdir/env/bin/python manage.py run_huey
Restart=always

[Install]
WantedBy=multi-user.target

之后我运行 sudo systemctl start gunicorn.sock。它有效但显示 active:dead 我不喜欢

于 2020-10-04T11:39:58.537 回答
0

我最终使用 supervisord 来运行 huey 我将 supervisord.conf /home/user。看起来像这样

[unix_http_server]
file=/tmp/supervisor.sock   ; the path to the socket file
chmod=0700                 ; socket file mode (default 0700)
chown=user:user       ; socket file uid:gid owner


[supervisord]
logfile=/home/user/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=1MB        ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=5           ; # of main logfile backups; 0 means none, default 10
loglevel=info                ; log level; default info; others: debug,warn,trace
pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false               ; start in foreground if true; default false
silent=false                 ; no logs to stdout if true; default false
minfds=1024                  ; min. avail startup file descriptors; default 1024
minprocs=200                 ; min. avail process descriptors;default 200
childlogdir=/home/medsjoin            ; 'AUTO' child log dir, default $TEMP

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface


[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[program:huey]
command=python manage.py run_huey              ; the program (relative uses PATH, can take args)
directory=/home/user/projectdir; directory to cwd to before exec (def no cwd)
autostart=true                ; start at supervisord start (default: true)
redirect_stderr=true          ; redirect proc stderr to stdout (default false)
stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=2     ; # of stdout logfile backups (0 means none, default 10)
stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=2     ; # of stderr logfile backups (0 means none, default 10)
environment =
  DJANGO_SETTINGS_MODULE="special.settings",
  PYTHONPATH="/home/user/projectdir/special",
  PATH="/home/user/projectdir/env/bin:%(ENV_PATH)s"

我从位于 /etc/systemd/system/supervisord.service 的 supervisord.service 开始

[Unit]
Description=supervisord daemon
Documentation=http://supervisord.org
After=network.target

[Service]
ExecStart=/usr/local/bin/supervisord -n -c /home/user/supervisord.conf
ExecReload=/usr/local/bin/supervisorctl -c /home/user/supervisord.conf reload
ExecStop=/usr/local/bin/supervisorctl -c /home/user/supervisord.conf shutdown

[Install]
WantedBy=multi-user.target

然后启动服务

sudo systemctl start supervisord.service

通过以下方式检查状态

sudo systemctl status supervisord.service

您可能还需要运行

sudo systemctl enable supervisord

注意 user rep 我的用户,projectdir:我的 django 项目所在的位置,project:我的 django 项目

于 2020-10-10T11:10:42.147 回答