Django模型保存不在守护程序模式下工作,而是与RunServer一起工作

发布于 2025-01-30 12:48:36 字数 1213 浏览 4 评论 0原文

一旦用户添加其github存储库,我将将github存储库保存到服务器,请参阅此模型。

class Repo(models.Model):
    url = models.CharField(help_text='github repo cloneable',max_length=600)
    def save(self, *args, **kwargs):
        # os.system('git clone https://github.com/somegithubrepo.git')
        os.system('git clone {}'.format(self.url))
        super(Repo, self).save(*args, **kwargs)

当我添加public github repo时,一切都在本地服务器和远程服务器(例如Digitalocean Droplet)(例如Digitalocean Droplet)中正常工作,这一切总是成功的。

当我这样运行服务器时,它可以正常工作:python3 manage.py runserver 0.0.0.0.0:800

但是当我使用Gunicorn和Nginx以守护程序模式运行时,它行不通,它不起作用,

一切都可以保存,甚至可以保存,数据库中的数据,只有它在守护程序模式下没有克隆,它怎么了?

这是我的枪支。

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=root
Group=www-data

WorkingDirectory=/var/www/myproject
Environment="PATH=/root/.local/share/virtualenvs/myproject-9citYRnS/bin"
ExecStart=/usr/local/bin/pipenv run gunicorn --access-logfile - --workers 3 --bind unix:/var/www/myproject/config.sock -m 007 myproject.wsgi:application

[Install]
WantedBy=multi-user.target

再次保证,一切都在起作用,即使是枪支,数据都保存在数据库中,只是它没有克隆github repo,甚至没有发出任何错误。\ \

这是怎么回事?有人可以帮我解决这个问题吗?

I am saving github repo to server once user add their github repo, see this models.

class Repo(models.Model):
    url = models.CharField(help_text='github repo cloneable',max_length=600)
    def save(self, *args, **kwargs):
        # os.system('git clone https://github.com/somegithubrepo.git')
        os.system('git clone {}'.format(self.url))
        super(Repo, self).save(*args, **kwargs)

Everything is working fine what I want in both local server and remote server like digitalOcean Droplet, when I add public github repo, the clone always success.

it works when I run the server like this: python3 manage.py runserver 0.0.0.0:800

But when I ran in daemon mode with gunicorn and nginx, it doesn't work,

Everything is working even saving the data in database, only it is not cloning in daemon mode, what's wrong with it?

this is my gunicorn.service

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=root
Group=www-data

WorkingDirectory=/var/www/myproject
Environment="PATH=/root/.local/share/virtualenvs/myproject-9citYRnS/bin"
ExecStart=/usr/local/bin/pipenv run gunicorn --access-logfile - --workers 3 --bind unix:/var/www/myproject/config.sock -m 007 myproject.wsgi:application

[Install]
WantedBy=multi-user.target

Note again, everything is working even the gunicorn, the data is saving in database, only it is not cloning github repo, even not firing any error.\

What's the wrong with this? can anyone please help me to fix the issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扭转时空 2025-02-06 12:48:36

在SystemD单元文件中,您可以使用Virtualenv的路径覆盖root User的PATH变量。因此,root用户在path中没有通常的项目,例如/usr/bin/bin通常存在git命令的位置。因此,您需要使用git的绝对路径,例如/usr/bin/git,或将git的bin目录添加到path,例如:

Environment="PATH=/usr/bin:/root/.local/share/virtualenvs/myproject-9citYRnS/bin"

In the systemd unit file, you overwrite the root user's PATH variable in Environment with the path of the virtualenv. Therefore the root user does not have the usual items in the PATH, e.g. /usr/bin where the git command usually exists. So you need to use the absolute path of git, e.g. /usr/bin/git, or add the git's bin directory to the PATH, for example:

Environment="PATH=/usr/bin:/root/.local/share/virtualenvs/myproject-9citYRnS/bin"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文