Ruby on Rails:使用“rails generate controller welcome”时权限被拒绝

时间:2014-05-23 06:35:11

标签: ruby-on-rails ruby ruby-on-rails-3

我在Red Hat服务器上使用Ruby on Rails。 当我尝试生成控制器文件时,我收到了这个错误:

[ec2-user@ip-172-31-22-128 testApp4]$ rails generate controller welcome
/home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:22:in `initialize': Permission denied @ rb_sysopen - /tmp/spring/fea371aaf9d69cfa58bd12f69b3f1bf6.pid (Errno::EACCES)
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:22:in `open'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:22:in `open'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:22:in `initialize'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:14:in `new'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:14:in `boot'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:43:in `block in boot_server'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:41:in `fork'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:41:in `boot_server'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:24:in `call'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/rails.rb:23:in `call'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
from /home/ec2-user/testApp4/bin/spring:16:in `require'
from /home/ec2-user/testApp4/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'

7 个答案:

答案 0 :(得分:33)

我通过运行

解决了这个问题
sudo chmod -R 1777 /tmp

希望这能帮助像我这样不喜欢停用弹簧宝石的其他人

答案 1 :(得分:8)

需要所有权来为每个服务器启动写入重写pid。

我必须用完整的本地路径运行它&amp;须藤

$ sudo chmod -R 777 / Users / MyName / Desktop / projects / my_project / tmp /

答案 2 :(得分:5)

我看了一下试图编写pid文件的库lib/spring/env.rb

有问题的函数每次尝试在同一位置创建一个临时目录,除非设置了XDG_RUNTIME_DIR

path = Pathname.new(File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, "spring"))

将所述变量设置为唯一目录对我来说很有用:

export XDG_RUNTIME_DIR=/tmp/`whoami`

答案 3 :(得分:3)

缺少tmp文件夹的可写权限。运行chmod 777 tmp/

答案 4 :(得分:0)

或者,

export XDG_RUNTIME_DIR=/run/user/${id -u}

更改此系统变量。 id -u返回您的UID(用户ID),这是您可以在/run/user/下有权写入/读取的目录名称。

答案 5 :(得分:0)

在Ubuntu 20.04中使用Rails 6应用程序时,我遇到了同样的问题。

每次我运行命令rails assets:clobber完全删除public/assets中的旧资产时,都会收到错误消息:

errno :: enotempty:目录不为空@ dir_s_rmdir

errno :: eacces:权限被拒绝@ apply2files

日志将指向导致该文件的文件的路径,在我的情况下,该文件就是public/packs/manifest.json文件。

我尝试删除它或更改权限,但是没有任何效果。我还尝试了删除项目中的tmp目录,但没有成功。

这是我修复的方式

我使用ls -lh命令列出了该目录中的所有文件和目录,这给了我以下输出:

-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem 1.7K Oct  6 20:29 404.html
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem 1.7K Oct  6 20:29 422.html
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem 1.6K Oct  6 20:29 500.html
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem    0 Oct  6 20:29 apple-touch-icon.png
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem    0 Oct  6 20:29 apple-touch-icon-precomposed.png
drwxr-xr-x 3 promisechukwuenyem promisechukwuenyem 4.0K Oct 13 09:20 armstrong_tools
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem    0 Oct  6 20:29 favicon.ico
drwxr-xr-x 3 root               root               4.0K Oct  8 13:06 packs
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem   99 Oct  6 20:29 robots.txt

我意识到对文件和目录的权限很好,但是packs目录具有root所有权,这与允许其他文件和目录是分开的:

drwxr-xr-x 3 root               root               4.0K Oct  8 13:06 packs

我只需运行以下命令即可将所有权从root更改为promisechukwuenyem:

sudo chown -R promisechukwuenyem:promisechukwuenyem packs/

现在,当我运行命令rails assets:clobber来完全删除public/assets中的旧资产时,它工作正常。

仅此而已。

我希望这会有所帮助

答案 6 :(得分:0)

我在使用 rails server 时遇到这种类型的错误(权限被拒绝 @ apply2files)。

sudo rails server 解决我的问题。