简体   繁体   English

为什么詹金斯启动我的django服务器会给我404,但手动运行相同的脚本才能正常工作?

[英]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.

相关问题 为什么 Django 只给我一个 url 模式的 404 错误? - Why does Django give me a 404 error for only one url pattern? 为什么这个脚本给我乱码? (蟒蛇) - Why does this script give me gibberish? (python) 为什么我的 Django 登录可以在开发服务器上运行而不是在生产服务器上运行? - Why does my Django login work on development server but not production server? 为什么无论输入如何,我的 python 都会给我相同的输出到列表中? - Why does my python give me the same output into a list no matter the input? 为什么我的 function 没有给我预期的 output - Why does my function does not give me the expected output 在 vs 代码的终端中运行 python 给我一个语法错误,但是,手动选择代码并运行它不会给我语法错误 - Running python in terminal in vs code gives me a syntax error, however, manually selecting the code and running it does not give me the syntax error 为什么我的django开发服务器在本地运行的速度要比在Heroku上运行同一开发服务器的速度快得多? - Why is my django development server running locally so much faster then running the same development server on Heroku? 为什么Atom中的脚本包不能与命令一起使用,而是手动操作? - Why does the script package in atom not work with command but does manually? Django 服务器不启动,启动时站点不工作 dockerfile - Django server does not start, the site does not work when starting dockerfile 为什么我的 Twitter stream 给我 HTTP 错误:406? - Why does my Twitter stream give me the HTTP Error: 406?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM