Django模型保存不在守护程序模式下工作,而是与RunServer一起工作
一旦用户添加其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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在SystemD单元文件中,您可以使用Virtualenv的路径覆盖root User的
PATH
变量。因此,root用户在path
中没有通常的项目,例如/usr/bin/bin
通常存在git命令的位置。因此,您需要使用git的绝对路径,例如/usr/bin/git
,或将git的bin目录添加到path
,例如:In the systemd unit file, you overwrite the root user's
PATH
variable inEnvironment
with the path of the virtualenv. Therefore the root user does not have the usual items in thePATH
, 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 thePATH
, for example: