服务器作为守护程序运行时的根路径问题 [英] root path issues when server is run as a daemon

查看:74
本文介绍了服务器作为守护程序运行时的根路径问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个访问文件系统的视图以及一些gems。在我将服务器作为守护程序运行之前,这似乎工作正常。 rails(4.2.3)

i have several views, as well as some gems, that access the filesystem. this seems to work fine until i run the server as a daemon. rails (4.2.3)

例如,在我的一个视图中,我访问应用程序根目录中的README文件

for example in one of my views I access the README file in the root of the app

File.read('README.md')

作为守护程序运行时,出现错误没有这样的文件或目录@ rb_sysopen-README.md

when running as a daemon, i get the error No such file or directory @ rb_sysopen - README.md

错误页面显示Rails.root路径,这是正确的。我可以通过以下方法解决此问题:

the error page shows the Rails.root path, which is correct. i CAN fix this problem by doing:

File.read("#{Rails.root}/README.md")

但是,这个问题不仅破坏了我的观点。似乎与Rails服务器有关。

however this issue breaks more than just my views. It would seem an issue with the rails server.

推荐答案

这是守护进程的工作方式- chdir 到/或另一个工作目录。一些程序允许您指定守护进程的工作目录。例如, puma 服务器默认使用当前目录,因此它可能对您有用。

This is how daemonized process works - chdir to / or another working directory. Some programs allow you to specify working directory for daemon process. For example puma server uses current directory by default so it might work for you.

这篇关于服务器作为守护程序运行时的根路径问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆