[英]Why does Jenkins starting my django server give me 404, but manually running the same script work properly?
This is my fabric script that runs on the jenkins server. 这是我在jenkins服务器上运行的结构脚本。
sudo('/home/myjenkins/killit.sh',pty=False)
sudo('/home/myjenkins/makedir.sh',pty=False)
sudo('/home/myjenkins/runit.sh',pty=False)
This kills the old server, creates a virtualenv, installs the requirements and restarts the server. 这将杀死旧服务器,创建virtualenv,安装要求并重新启动服务器。
The problem is the with the script that starts the server - runit.sh :- 问题在于启动服务器的脚本-runit.sh:-
nohup /home/myjenkins/devserver/dev/bin/python /home/myjenkins/devserver /workspace/manage.py runserver --noreload 0:80 >> jenkins.out &
When the jenkins server that starts the server and I navigate to the homepage, it gives me a 404 Page Not Found. 当jenkins服务器启动服务器并且我导航到主页时,它给了我404页面未找到的信息。 It says /static/index.html not found.
它说/static/index.html未找到。 But the file exists.
但是该文件存在。 When I run 'sudo bash runit.sh' and I access the homepage, It works fine.
当我运行“ sudo bash runit.sh”并访问主页时,它工作正常。
mkdir -p /home/myjenkins/devserver
cp -rf /home/myjenkins/workspace /home/jenkins/devserver/
cp -f /home/myjenkins/dev_settings.py /home/myjenkins/devserver/workspace/mywebsite/settings.py
cd /home/myjenkins/devserver
virtualenv -p python3 dev
cd /home/myjenkins/devserver/workspace
../dev/bin/pip install -r requirements.txt
Please ask me for more details if you need it. 如果需要,请询问我更多详细信息。
EDITED 9/2/18 编辑9/2/18
When I start the script from the folder containing manage.py, the server is able to serve the files. 当我从包含manage.py的文件夹中启动脚本时,服务器可以提供文件。 But Jenkins was starting the script from the home folder and if I also start the script from the home folder - the server is not able to find the files.
但是Jenkins是从主文件夹启动脚本的,如果我也从主文件夹启动脚本,则服务器将无法找到文件。 look at my comment for more details.
查看我的评论以获取更多详细信息。 It would be great if someone could explain why this happens even though I've specified the full path in the script.
即使有人在脚本中指定了完整路径,也可以有人解释为什么会发生这种情况,这将是很好的。
nohup /home/myjenkins/devserver/dev/bin/python /home/myjenkins/devserver /workspace/manage.py runserver --noreload 0:80 >> jenkins.out &
Okay I figured out the whole deal. 好吧,我知道了整个交易。 My django server was taking the output of the npm build from the wrong folder.
我的django服务器从错误的文件夹获取了npm build的输出。
In the settings.py file, the variable STATICFILES_DIRS
was set as:- 在settings.py文件中,变量
STATICFILES_DIRS
设置为:-
STATICFILES_DIRS = ('frontend/dist',)
instead of:- 代替:-
STATICFILES_DIRS = (os.path.join(BASE_DIR,'frontend/dist'),)
Thus, when Jenkins was running the script, it was doing so from the home folder. 因此,当詹金斯(Jenkins)运行脚本时,它是从home文件夹运行的。 This made Django's staticfiles finders to look at /home/myjenkins/frontend/dist instead of the relative '../frontend/dist'
这使得Django的staticfile查找器可以查看/ home / myjenkins / frontend / dist而不是相对的'../frontend/dist'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.